Question bankPricingSign in

Single Number (XOR)

Bit ManipulationEasy1:00

Given a non-empty array of integers where every element appears exactly twice except for one element that appears once, find that single element.

For example, given [2, 2, 1], the answer is 1. Given [4, 1, 2, 1, 2], the answer is 4.

Explain how you would solve this in O(n) time and O(1) space. What property of a specific bitwise operation makes this possible?

How to approach it

  • Hint 1

    Think about what happens when you XOR a number with itself.

  • Hint 2

    XOR has useful properties: a ^ a = 0, a ^ 0 = a, and it is commutative and associative.

  • Hint 3

    If you XOR all elements together, what survives?

Ready to answer it out loud?

Record your answer in 1:00 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.