Skip to the code
cf.
+10 XP

#671 Find the Unpaired Request

easy

A network log records request IDs. Every request appears twice, once when it starts and once when it finishes, except one request that never finished.

Write unfinishedRequest(ids) that returns that ID. Use O(1) extra memory.

Example 1

Input: ids = [7,3,5,3,5]
Output: 7

3 and 5 appear twice. 7 appears once.

Example 2

Input: ids = [7]
Output: 7

The only request never finished.

Constraints

  • 1 <= ids.length <= 3 × 10^4, and the length is odd
  • -2^31 <= ids[i] <= 2^31 - 1
  • Exactly one ID appears once; every other ID appears exactly 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).