Remove Duplicates Inplace(Contest)
Remove Duplicates Inplace easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Remove Duplicates Inplace easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Given a sorted array, remove the duplicates in place such that each element appears at most twice and returns the new length.
Note that even though we want you to return the new length, make sure to change the original array as well in place
Do not allocate extra space for another array, you must do this in place with constant memory. Input First-line will contain a single integer N denoting array length Second-line will contain the elements of the array
Constraints: 1 <= N <= 10^5 1 <= A[i] <= 10^5 Output Print the length of the final array Example Sample Input: 4 1 1 1 2
Sample Output: 3
Explanation:- A is now [1,1,2].
Sample Inpiut: 3 1 2 3
Sample Output: 3
link: