logo
Interview
    Interview Guide
    Coding Problems List
Sponsored: Coursera
Problems

Lonely Integer

Problem

There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once.

Solution

XOR: a ^ a = 0, 0 ^ a = 0, a ^ x ^ a = x

Apply XOR to all numbers, the result will be the lonely integer.

Online Judge