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.
counter =0# We use while loop to try and cut down on 2 loopswhile counter < (len(nums)-1):# if current counter is the same as the next one# remove currentif nums[counter]== nums[counter +1]: nums.remove(nums[counter])else:# else they are not the same, so counter +=1 counter +=1returnlen(nums)