Loading
Loading
At the end of a conference, every visitor badge is scanned twice: once at entry and once at exit. One visitor left through a side door, so their badge was scanned only once.
Given the list of scanned badges, in which every ID appears exactly twice except one that appears once, return that unpaired ID.
badges = [4, 7, 2, 7, 4]acc = 0startacc = 40 ^ 4acc = 3100 ^ 111 = 011acc = 1011 ^ 010 = 001acc = 6001 ^ 111 = 110acc = 2110 ^ 100 = 010 — the pairs cancelled, 2 remains2Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
4 and 7 each appear twice; 2 has no partner.
Example 2
Negative IDs cancel the same way; -3 is left.