The Remove Duplicates from Sorted Array interview question is a foundational in-place array manipulation problem. Given a sorted array of integers, you must remove all duplicate values so that each element appears only once, modifying the array in-place and returning the new length. The elements beyond the new length do not matter. No extra array space is allowed.
This is one of the most frequently asked warm-up problems at companies like Apple, Uber, Microsoft, Meta, Amazon, and Google because it directly tests the two-pointer technique — one of the most versatile tools in array manipulation. It also evaluates whether candidates can think in terms of in-place modification, a concept relevant to memory-constrained systems and embedded software.
The pattern is the two-pointer technique. Use a slow pointer k to track the position of the last unique element written, and a fast pointer i to scan through the array. Whenever nums[i] differs from nums[k], increment k and copy nums[i] to nums[k]. After the scan, k + 1 is the new length.
Array: [1, 1, 2, 3, 3, 4]
nums[1]==nums[0] → skip.nums[2]=2 ≠ nums[0]=1 → k=1, nums[1]=2. Array: [1,2,2,3,3,4].nums[3]=3 ≠ nums[1]=2 → k=2, nums[2]=3.nums[4]=3 == nums[2]=3 → skip.nums[5]=4 ≠ nums[2]=3 → k=3, nums[3]=4.New length: 4. First 4 elements: [1, 2, 3, 4].
k instead of k+1.For the Remove Duplicates from Sorted Array coding problem, the two-pointer array interview pattern is essential to master. Practice explaining the role of each pointer before coding — fast pointer for reading, slow pointer for writing. This exact pattern extends to Remove Duplicates from Sorted Array II and Remove Element, so mastering it here builds a reusable mental model. Interviewers at Infosys and Wipro often use this as an entry-level screen, so practice explaining it in simple terms.