class Solution:
def getFolderNames(self, names: List[str]) -> List[str]:
""" tc O(N) sc O(N)
1. initialize res, seen as set, a dictionary to record max cnt for key x has appeared
2. each time get an entry, extract cnt, and candidate key x
3. if current candidate key has appeared before, increment cnt by 1 and check if revised key has appeared before untill new key is not used before, update the key
4. update set, dictionary's key and value, and update result
"""
res = []
seen = set()
d =collections.defaultdict(int)
for x in names:
cnt = d[x]#d.get(x,0) if x not in d before, return 0
#print(cnt)
cur = x
while cur in seen:
cnt += 1
cur = f'{x}({cnt})'
d[x] = cnt
res.append(cur)
seen.add(cur)
return res