FunctionRacerProblemsRace

Remove Adjacent Duplicates in Groups of K

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

Whenever k equal letters sit next to each other, delete all k of them and let the left and right parts join up. Keep doing this until no group of k equal neighbours is left, and return the string. The result does not depend on the order of deletions.

Example 1

s "deeedbbcccbdaa"
k 3
returns "aa"

Remove eee, then ccc, then bbb, then ddd: left with aa.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems