Loading...
Loading...
Loading...
A sorted list of seat numbers may repeat. Keep each number at most twice and remove the extra copies in place. Print the new length on the first line and the kept numbers on the second.
Example
Input
1 1 1 2 2 3 3 3 3
Output
6 1 1 2 2 3 3
Try the problem first. Open one hint at a time.
Keep a write index. Compare each value with the value two places behind it in the kept part.
A value is kept if fewer than two values are kept so far, or it differs from nums[write - 2].
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor