class Solution:
def longestDiverseString(self, a: int, b: int, c: int) -> str:
""" tc O(N) sc O(N)
main idea: greedy
assuming a >=b >=c
there are 2 cases (1) a > 0, b=c=0, to produce longest, do aa* min(2,a)
(2) a >= b >= 1 : for use_a, do min(2,a); for b if new_a < b: dont add b after a this time => because if you follow with b, if c == 0, next round b > a, b will use 2 cards => !!!! we have bbb
"""
def helper(a,b,c,aa,bb,cc): # a >= b >= c
if a < b :
return helper(b,a,c,bb,aa,cc)
if b < c :
return helper(a,c,b,aa,cc,bb)
# Case1
if b == 0:
return aa * min(2,a)
# Case2
used_a = min(a,2)
used_b = 1 if a - used_a >= b else 0
return aa*used_a +bb*used_b + helper(a-used_a,b-used_b,c,aa,bb,cc)
return helper(a,b,c,"a","b","c")