class Solution: def longestDiverseString(self, a: int, b: int, c: int) -> str: dic = {'a': a, 'b': b, 'c': c } ans = '' while True: low, mid, high = sorted(dic.keys(), key=lambda x: dic[x]) if (len(ans) <2 or not ans[-1] == ans[-2] == high) and dic[high]: ans += high dic[high] -= 1 elif dic[mid]: ans += mid dic[mid] -= 1 else: break return ans