Ctrl K

XOR of Repeat Badges

Easy
An office turnstile logs badge numbers into the array badges. Each employee passes through once or twice a day, so every number shows up in the log either once or twice. Return the bitwise XOR of all numbers that appear in the log **exactly twice**. If there are none, return 0.
Example 1
badges=[7, 3, 7, 12] → 7

Only badge 7 was scanned twice, so the answer is 7.

Example 2
badges=[5, 9, 9, 5, 4] → 12

Badges 5 and 9 appear twice: 5 XOR 9 = 0101 XOR 1001 = 1100 = 12.

Example 3
badges=[2, 8, 6] → 0

Nothing repeats, so the result is 0.

Constraints
  • 1 ≤ badges.length ≤ 50
  • 1 ≤ badges[i] ≤ 50
  • Every number appears in badges once or twice
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Lost Ticket EasyDoubled Tag, Lost Tag EasyWords From Working Keys EasyIn at Least Two Lists EasyMatching Sock Pairs Easy
loading Python…
Input
badges=[7, 3, 7, 12]
Expected
7

Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.