algorythms
Two Pointers
LC #26Easy

Remove Duplicates from Sorted Array

Two Pointers
AmazonMicrosoftGoogle

Problem

Remove duplicates from a sorted array in-place and return the count of unique elements.

arraytwo-pointers

Constraints

  • 1 ≤ n ≤ 3 × 10⁴
  • -100 ≤ nums[i] ≤ 100
  • nums is sorted in non-decreasing order

Example

Inputnums = [1, 1, 2]
Output2
Why

Array becomes [1, 2, _]. Return k = 2 unique elements

Hints — reveal one at a time