We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Bit Manipulation
  4. Lonely Integer

Lonely Integer

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Given an array of integers, where all elements but one occur twice, find the unique element.

Example

The unique element is .

Function Description

Complete the lonelyinteger function in the editor below.

lonelyinteger has the following parameter(s):

  • int a[n]: an array of integers

Returns

  • int: the element that occurs only once

Input Format

The first line contains a single integer, , the number of integers in the array.
The second line contains space-separated integers that describe the values in .

Constraints

  • It is guaranteed that is an odd number and that there is one unique element.
  • , where .

Sample Input 0

1
1

Sample Output 0

1

Explanation 0

There is only one element in the array, thus it is unique.

Sample Input 1

3
1 1 2

Sample Output 1

2

Explanation 1

We have two 's, and is unique.

Sample Input 2

5
0 0 1 2 1

Sample Output 2

2

Explanation 2

We have two 's, two 's, and one . is unique.

Author

dheeraj

Difficulty

Easy

Max Score

20

Submitted By

157940

Need Help?


View discussions
View editorial
View top submissions
RESOURCES

  • Bitwise XOR
  • Caching

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy