You are given an array
arr[]
of size
n
with duplicate elements, write a program to
remove all duplicates
from the array, and return the size of the new array.
Problem Notes
- All elements of the resultant array must be unique.
- It's better if the algorithm is in-place.
Example 1
Input: arr[] = [-1, 0, 1, 1, 2, 9, 9]
Output: 5
Explanation: The new array will be [-1, 0, 1, 2, 9] i.e. having length 5.
Example 2
Input: arr[] = [-10, 1, 3, 6, 6, 6, 6, 10]
Output: 5
Explanation: The new array will be [-10, 1, 3, 6, 10] having length 5 after removing repeated element 6.
Example 3
Input: arr[] = [10, 20, 30, 33, 45]
Output: 5
Explanation: No elements were repeated
Example 4
Input: arr[] = [1, 1, 1, 1, 1, 1]
Output: 1
Explanation: The only unique element was 1