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. Bit Manipulation: Lonely Integer

Bit Manipulation: Lonely Integer

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Consider an array of integers where all but one of the integers occur in pairs. In other words, every element occurs exactly twice except for one unique element. Find the unique element.

For example, given the array , you would return .

Function Description

Complete the findLonely function in the editor below. It should return the unique integer in .

findLonely has the following parameter(s):

  • arr: an array of integers

Input Format

The first line contains a single integer, , denoting the number of integers in .
The second line contains space-separated integers, each an element, .

Constraints

  • It is guaranteed that is an odd number.
  • , where .

Output Format

Print the unique number in on a new line.

Sample Input 0

1
1

Sample Output 0

1

Explanation 0
The array only contains a single , so we print as our answer.

Sample Input 1

3
1 1 2

Sample Output 1

2

Explanation 1
We have two 's and one . We print , because that's the only unique element in the array.

Sample Input 2

5
0 0 1 2 1

Sample Output 2

2

Explanation 2
We have two 's, two 's, and one . We print , because that's the only unique element in the array.

Author

dheeraj

Difficulty

Easy

Max Score

20

Submitted By

36144

Need Help?


View discussions
View editorial
View top submissions
RESOURCES

  • Binary Numbers and Bit Manipulation

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