We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- String Construction
- Discussions
String Construction
String Construction
Sort by
recency
|
977 Discussions
|
Please Login in order to post a comment
include
using namespace std; int test(string s) { map mp; int sum = 0; for(int i = 0; i < s.length(); i++) { mp[s[i]]++; } for(auto it : mp) { if(it.second = 1) { sum += 1; } else if(it.second >= 2) { sum += 2; } } return sum; } int main() { int t; cin >> t; while(t--) { string s; cin >> s; cout << test(s) << endl; } return 0; }
C++ One Liner
The solution here is to count the number of unique occurrences of the characters, here is the explanation : https://youtu.be/UqqNcIUnsv8
solution 1 : using map
solution 2 : using set
Python3
def stringConstruction(s):
Java