#C10839. Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Given a sorted array of integers, your task is to remove duplicates in place such that each element appears only once and return the new length of the array. The relative order of the elements must be preserved.
You are required to use an in-place algorithm with O(n) time complexity and O(1) extra space. This is a classic problem that can be solved using the two-pointer technique.
Note: The input array is provided in non-decreasing order.
inputFormat
The first line contains an integer n, which is the number of elements in the sorted array. The second line contains n space-separated integers representing the array.
outputFormat
Output a single integer that indicates the number of unique elements in the array after duplicates have been removed.## sample
3
1 1 2
2