You are viewing a single comment's thread. Return to all comments →
Here is my c++ easy solution, explantion here : https://youtu.be/WAPtXpj-PSU
int validSize(string s, char first, char second){ string ans = ""; for(int i = 0; i < s.size(); i++){ if(s[i] == first || s[i] == second){ if(ans.size() > 0 && ans[ans.size() - 1] == s[i]) return 0; else ans+=s[i]; } } if(ans.size() < 2) return 0; return ans.size(); } int alternate(string s) { int ans = 0; for(char i = 'a'; i < 'z'; i++){ for(char j = i + 1; j <= 'z'; j++){ int r = validSize(s, i, j); if(r > ans) ans = r; } } return ans; }
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 →
Here is my c++ easy solution, explantion here : https://youtu.be/WAPtXpj-PSU