Skip to main content

Practice · 3 of 5

Remove adjacent duplicates

CHALLENGE
Difficulty: beginner+25 XP

Implement void removeAdjacentDuplicates(ArrayList<String> list): mutate the list so any run of equal neighboring elements collapses to one — ["a","a","b","b","b","c"] becomes ["a","b","c"]. Mind the shifting trap: walk BACKWARDS.

Back to lesson: Practice: List practice