50 cases Time limit 1000 ms total Memory 256 MB
A row of balloons is tied along a string, each one a colour numbered 0 to 9.
Whenever two balloons of the same colour end up next to each other, they both pop, and
the balloons on either side slide together. That can bring two more of the same colour
together, and those pop too.
Keep popping until no two neighbours share a colour, and return the balloons that are left.
Constraints:
len(l) ≤ 20Examples:
f([1, 2, 2, 1, 3]) returns [3] (the 2s pop, then the 1s meet and pop)
f([1, 1, 1]) returns [1]
f([1, 2, 3, 3, 2, 2, 1]) returns [1, 2, 1]
f([]) returns []
[[1, 2, 2, 1, 3]]
[3]
[[1, 1, 1]]
[1]
[[1, 2, 3, 3, 2, 2, 1]]
[1, 2, 1]
[[]]
[]