Keep only the first two occurrences of each element
Filed under OneStack
The question
Given an integer array with repeats, keep the first and second occurrence of each value and delete third and later occurrences (example [0,1,1,2,5,3,1,3,3,3,5,5] gives [0,1,1,2,5,3,3,5]).
No write-up yet. Related questions below have one.
Related OneStack questions
Collected from public candidate posts and coding forums. Updated Nov 2026.