Longest Happy String
Longest Happy String
public:
string longestDiverseString(int a, int b, int c) {
string res = "";
vector<pair<int, char>> counts = {{a, 'a'}, {b, 'b'}, {c, 'c'}};
while (true) {
// Sort counts in descending order by the number of occurrences
sort(counts.rbegin(), counts.rend());
int n = res.size();
// If the last two characters in the result are the same as the
current character, skip this character for now
if (n >= 2 && res[n - 1] == ch && res[n - 2] == ch) continue;
return res;
}
};