Find the unique element in an array where all elements appear twice except one.
Examples:
[1, 1, 4, 4, 7, 8, 8, 29, 29] → 7[1, 2, 2, 3, 3] → 1
Summary (with approach)
Use XOR: since a ^ a = 0, a ^ 0 = a, and XOR is associative/commutative, XOR all numbers; the result is the single number. Runs in O(N) time and O(1) space. Alternative: hash counting in O(N) space.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including OpenAI, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.