Find Odd Occurrence Element

You are given an array of 'N' elements. In this given array, each element appears an even number of times except one element which appears odd no. of times. Your task is to find the element which occurs an odd number of times.

For example :
Input array [5,5,6,4,6],If we look at the frequency of different elements in this array.We can see,4 appears an odd number of times, so our answer will be 4.
Input Format :
The first line of input contains a single integer 'T', representing the number of test cases.
Then the 'T' test cases follow.

The first line of each test case contains a number 'N' denoting the size of the array.
The second line contains 'N' space-separated distinct integers denoting elements of the array.
Output format :
For each test case print the element which appears an odd number of times.

The output of every test case will be printed in a separate line. 
Note :
You don’t have to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1<= T <=100
1 <= N <= 10000
1 <= ARR[i] <= 10^8

Where 'T' denotes the number of test cases, 'N' denotes the number of elements in the array, and 'ARR[i]' denotes the 'i'th' element of the array 'ARR'.

Time limit : 1 sec
CodingNinjas
author
2y
Brute force

We will find the frequency of all elements by iterating over the whole array N times. On completion of iteration if the frequency of element is odd. We will return this element else keep on...read more

CodingNinjas
author
2y
Hashing Technique

We will scan the array from left to right and we will use the Hash to store frequency of each element. On encountering an element we will increase its hash value by 1.No we will scan ...read more

CodingNinjas
author
2y
XOR

As XOR value of two same elements is zero and XOR of any element, say X, with 0 is X.We can use this fact in our problem, as if we XOR all elements of the array, then elements which appear even no....read more

Add answer anonymously...
Jupiter Money Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter