Playing Hacks and Stuffs!
My first approach to solve this works but the issue was the order of the return value wasn’t the same in the original string which made it fail
But here’s the solve script:
def removeDuplicates(s, k):
ht = {}
r = []
for i in s:
if i in ht:
ht[i] += 1
else:
ht[i] = 1
for key, value in ht.items():
check = value % k
if check < k:
r.append(key * check)
return "".join(r)
s = "yfttttfbbbbnnnnffbgffffgbbbbgssssgthyyyy"
k = 4
r = removeDuplicates(s, k)
print(r)
So I implemented another appraoch which made us of Stack Data Structure
Here’s my solve script: link