Skip to the code
cf.
+25 XP

#73 Duplicate Upload IDs

medium

An upload queue gives each of n uploads an id from 1 to n. A retry bug made some ids appear twice (none appear more than twice). The ids are in ids.

Write duplicateIds(ids) that returns every id that appears twice, in increasing order. Use O(1) extra memory besides the answer.

Example 1

Input: ids = [5,3,1,5,3,2]
Output: [3,5]

3 and 5 each appear twice.

Example 2

Input: ids = [1,2,3]
Output: []

No id repeats.

Constraints

  • 1 <= ids.length <= 10^5
  • 1 <= ids[i] <= ids.length
  • Each id appears once or twice.
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).