Remove Duplicates from Sorted Array

Fundamentals & Basic Operations DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Removing Duplicates from a Sorted Array in Place, Arrays, Hashing, Two Pointers, Time Complexity, Space Complexity, sorting algorithms, set, data structures, algorithms, two pointer technique, Sets & Hash Sets, Two-Pointer Technique, Data Structures.

Problem Statement: Given an integer array arr sorted in non decreasing order, remove the duplicates in place such that each unique element appears only once. The relative order of the elements should be kept the same. If there are k elements after removing the duplicates, then the first k elements of the array should hold the final result. It does not matter what you leave beyond the first k elements. Return k after placing the final result in the first k slots of the array. Input Specification: The input consists of a single integer array arr. Output Specification: Return an integer k, representing the number of unique elements. The input array arr should be modified in place such that its first k elements contain the unique elements in their original relative order. Examples: Example 1: Example 2: