Dsa
Two Pointers
Medium
Remove Duplicates from Sorted Array II
Given a sorted array containing duplicates, modify the array in-place such that each unique element can appear at most twice. Return the new length of the modified array. Note that you must do this in-place and not allocate extra space for another array.
Example:
Input:
1 1 1 2 2 3
Output:
5
Key concepts
two_pointersarrayduplicates
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now