DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Remove Duplicates from Sorted Array

**Problem Statement:** Given an integer array `nums` 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. Return the number of unique elements in `nums`. **Hint / Expected Approach:** Two-pointer in-place write **Edge Cases to Consider:** - (1) All duplicates - (2) No duplicates - (3) Single element

Examples

Example 1
Input: [1,1,2]
Output: [1,2]
Example 2
Input: [0,0,1,1,1,2,2,3,3,4]
Output: [0,1,2,3,4]
Example 3
Input: [1]
Output: [1]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪All duplicates
  • ▪No duplicates
  • ▪Single element
Frequently Asked At
MicrosoftAmazonTCSWiproInfosys