X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Single Number
Easy Accuracy: 56.37% Submissions: 2119 Points: 2

Given an array Arr of positive integers of size N where every element appears even times except for one. Find that number occuring odd number of times.

Example 1:

Input: 
N = 5
Arr[] = {1, 1, 2, 2, 2}
Output: 2
Explanation: In the given array all
element appear three times except 2
which appears once.

Example 2:

Input: 
N = 7
Arr[] = {8, 8, 7, 7, 6, 6, 1}
Output: 1
Explanation: In the given array all
element appear three times except 1
which appears once.

Your Task:  
You don't need to read input or print anything. Your task is to complete the function getSingle() which takes the array of integers arr[] and n as parameters and returns a integer denoting the answer.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Constraints:
1 <= N <= 107
0 <= Arri <= 108

 

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Single Number

Output Window