Missing Number

Given an array ‘ARR’ of ‘N’ integers, where all the elements occur an even number of times and only one number occurs an odd number of times. Find the number which occurs an odd number of times.

EXAMPLE:
Input: 
'N' = 5
'ARR' = 1 2 3 2 3

Output: 1

Except for number 1 all numbers occur even number of times.
Input Format :
The first line will contain integer 'T', the number of test cases. For each test case, there will be only two lines.

The first line contains a single integer, 'N' representing the size of the array.
The second line contains ‘N’ spaced integers.
Output format :
For each test case, print a single integer representing the number occurring odd number of times.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= 'T' <= 10
1 <= 'N' <= 10^4
1 <= ARR[i] <= 10^5
Time Limit: 1 sec
CodingNinjas
author
2y

Calculate the sum of first n natural numbers as sumtotal= n*(n+1)/2
Create a variable sum to store the sum of array elements.
Traverse the array from start to end.
Update the value of sum as sum = sum + ...read more

CodingNinjas
author
2y
Brute Force

Approach:

We will run two nested loops and count the occurrence of every element.

If at any moment, we are getting the count as odd, we will just print that element.

Algorithm :

  • For i = ...read more
CodingNinjas
author
2y
Hashing

Approach:

We will hash be using a hash data structure, so here we will store the frequency of an element ‘ARR[i]’ at ‘hash[ARR[i]]’.

Each time we encounter a number ARR[i] we will increase the ...read more

CodingNinjas
author
2y
Bitwise XOR

Approach:

The bitwise Xor all elements of the array where even occurring elements on Xor will give 0 whereas odd occurring element on xor give us the number since its even occurrence will ...read more

Add answer anonymously...
Nagarro Software Developer 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