* Since the array is sorted, duplicate elements are adjacent. * Keep one pointer (slow) at the last unique element and * another pointer (fast) to scan the array. * Approach: * - Initialize slow ...
Explanation: Total number of unique elements are 3, i.e[1,2,3] and Therefore return 3 after assigning [1,2,3] in the beginning of the array. Explanation: Total number of unique elements are 4, i.e[1,2 ...
Automatically sorted: When elements are added to a TreeSet, they are automatically sorted in ascending order. Does not allow duplicates: If you try to add an element that already exists, it will be ...