Participate in Codex, Test Your Skills & Win BIG

Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Input Format:

    First and only argument of input contains an integer array A

Output Format:

    return a single integer denoting single element


2 <= N <= 2 000 000  
0 <= A[i] <= INT_MAX

For Examples :

Example Input 1:
    A = [1, 2, 2, 3, 1]
Example Output 1:
    3 occurs only once
Example Input 2:
    A = [1, 2, 2]
Example Output 2:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Single Number on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions