Your question is Remove Duplicate Characters. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Spotify metadata pipelines sometimes need to reduce repetitive characters in playlist and track text without changing the original order. Given a string and a non-negative integer max_duplicates, remove excess occurrences so that each character appears at most max_duplicates + 1 times.
The first occurrence is not considered a duplicate. Keep the earliest occurrences and discard later ones once the limit is reached.
Implement limit_duplicates(s, max_duplicates).
s, a string, and max_duplicates, a non-negative integer.def limit_duplicates(s, max_duplicates):