K13

Remove Duplicates from Sorted Array

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: ARRAY

Problem Statement & Objective

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 array modified in-place containing only the unique elements in their original sorted order.

Function Signature (Python)

remove_duplicates(nums: list[int]) -> list[int]

Input & Output Contract

Output Rule:Array of unique elements in sorted order.

System Constraints

0 <= sayilar.length <= 3 * 10^4
-100 <= sayilar[i] <= 100
sayilar is sorted in non-decreasing order

Example Execution Walkthrough

sayilar = [1, 1, 2]
result: [1, 2]

Example Test Scenarios (3)

Example 1
Input:[[1,1,2]]
Expected Output:[1,2]
Example 2: 5 Benzersiz
Input:[[0,0,1,1,1,2,2,3,3,4]]
Expected Output:[0,1,2,3,4]
Example 3: Boş Dizi
Input:[[]]
Expected Output:[]
Loading Python Editor...
Input Parameters
[
  [
    1,
    1,
    2
  ]
]
Expected Output
[
  1,
  2
]