Skip to content

ORIGINAL CODING QUESTION

Unpaired event badge

At a campus hiring event every badge ID was scanned exactly twice, once at entry and once at exit, except for one badge that was scanned only once. Return that badge ID. Scans are not in any particular order.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

First integer n (odd), then n badge IDs. Print the unpaired ID.

Constraints

1 ≤ n ≤ 199; -1000 ≤ ID ≤ 1000; exactly one ID appears once and every other ID appears exactly twice.

Example 1

Input

5
4 7 4 9 7

Output

9

IDs 4 and 7 appear twice; 9 appears once.

Example 2

Input

1
-6

Output

-6

The only scan is the unpaired badge.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

A frequency map works, but there is a constant-space trick.

Hint 2

XOR of a value with itself is 0, and XOR of a value with 0 is the value.

Hint 3

XOR all IDs together; every pair cancels and only the unpaired ID remains.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →