# intuition: store the up to date/current index in the hash map
# need to keep track of number of deletion/merge
# hash map will store the char index
hash = defaultdict(int)
new_str = ''
# keep track deletion count so that the char index is up to date to the new_str index
del_count = 0
for i, char in enumerate(s):
# print(f'new_str={new_str}, del_count={del_count}')
if char not in hash:
hash[char] = i - del_count
new_str += char
elif char in hash:
if i - hash[char] - del_count > k:
hash[char] = i - del_count
new_str += char
else:
# remove char -> don't write to new_str
del_count += 1
return new_str