k
to the end, incrementing the count of each flavor in the hash table.res
to store the maximum number of unique flavors you can keep, initially set to the number of unique flavors in the hash table.k
, for each candy:
a. Decrement the count of the flavor in the hash table.
b. If the count becomes zero, remove the flavor from the hash table.
c. Increment the count of the flavor that is k
positions before the current candy in the hash table.
d. Update res
with the maximum of its current value and the size of the hash table.res
as the final result.