Skip to the code
+25 XP

#673 Two Unpaired Session IDs

medium

An auth server logs each session ID at login and again at logout. Two sessions never logged out, so their IDs appear once; every other ID appears exactly twice.

Write openSessions(ids) that returns the two unpaired IDs as [smaller, larger]. Use O(1) extra memory.

Example 1

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

1 and 2 appear twice. 3 and 5 appear once.

Example 2

Input: ids = [-1,0]
Output: [-1,0]

Both IDs appear once.

Constraints

  • 2 <= ids.length <= 3 × 10^5
  • -2^31 <= ids[i] <= 2^31 - 1
  • Exactly two different IDs appear once.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

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