You are viewing a single comment's thread. Return to all comments →
Instead of looping from 'a' to 'z' you can easily find distinct character in string using sets.
set<char> set; int size; cin >> size; string s; cin >> s; // find distint char for(char a : s){ set.insert(a); } int m = 0; if(s.length() > 1){ for( auto a : set){ for(auto b : set){ if(a == b) continue; int n = count_alternating(s,a,b); if(n > m) m = n; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
Instead of looping from 'a' to 'z' you can easily find distinct character in string using sets.