Skip to the code
cf.
+10 XP

#108 Dedupe a Sorted Version List

easy

A package manager collects the build numbers of a dependency from many lockfiles into versions, sorted ascending. The same build number can appear many times.

Write dedupeVersions(versions) that removes the repeats in place so each build number appears once, in ascending order, and shortens the array to the kept items. Don't create a second array. The tests check versions after your function runs.

Example 1

Input: versions = [2,2,3,5,5,5,8]
Output: [2,3,5,8]

Each build number is kept once.

Example 2

Input: versions = [1,4,6]
Output: [1,4,6]

There are no repeats to remove.

Constraints

  • 0 <= versions.length <= 100000
  • versions is sorted ascending.
  • -10^6 <= versions[i] <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).