Remove Duplicates from Sorted Array

If a question mentions a specific property about the input data, often the optimal solution will make use of this property.

In this case, we are told that the array is sorted. That means our optimal solution must make use of the fact it is sorted.

Listen carefully to what your interviewer is telling you, every word might come in handy.

Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

Last updated