nums is sorted in increasing order. Return the list where each value appears at most twice (extra copies removed), keeping the order. For [1, 1, 1, 2, 2, 3] the answer is [1, 1, 2, 2, 3].
Try to solve it with one pass and two pointers: a write pointer for the answer and a read pointer for the input.
Example 1
Input:
keep_at_most_twice([1, 1, 1, 2, 2, 3])
Output:
[1, 1, 2, 2, 3]
Example 2
Input:
keep_at_most_twice([0, 0, 1, 1, 1, 1, 2, 3, 3])
Output:
[0, 0, 1, 1, 2, 3, 3]
0 <= len(nums) <= 200000nums is sorted in increasing order.No results yet
Run your code to check it against the examples, or submit to run every test.