Example with more than two duplicates
Input
nums = [1, 1, 1, 2, 2, 3]
Output
[1, 1, 2, 2, 3]
Each number is allowed at most two times. The first three 1s become two 1s.
Full lesson preview
Given a sorted array, remove duplicates in-place allowing each element to appear at most twice. Return the resulting prefix as a list.
Problem statement
Task
Examples
Input
nums = [1, 1, 1, 2, 2, 3]
Output
[1, 1, 2, 2, 3]
Each number is allowed at most two times. The first three 1s become two 1s.
Input format
Output format
Constraints
Samples
Input
nums = [0, 0, 1, 1, 1, 1, 2, 3, 3]
Output
[0, 0, 1, 1, 2, 3, 3]
Trim extra occurrences so each number appears at most twice.