Problem 2: Odd one out
In the given list of integers, every integer is repeated even number of times except one of them. Find the integer which is repeated odd number of times.
First line contains number of test cases T.
Then T test cases follow. First line for each test case contains number of elements N in the list and in next line, there are N integers separated by a single white-space character.
The output file contains T lines.
For each test case, print the integer which is repeated odd number of times.
The list contains 32-bit integers.
3 5 1 2 1 2 3 9 4 5 4 7 5 4 5 4 5 3 9 6 6
3 7 9
B: Number of square brackets which are [ and ]
S: Number of * and /
C: Total number of non-whitespace characters
T=10000/(C + 400*B + 100*S)
A brute-force approach for this problem is to maintain an array of input integers and we count number of occurences of all unique integers in the array.
But this method does not score good as use of array is restricted through pointers and square brackets.
There is an alternate solution to this problem by bitwise operator XOR(^). We know:
1. A^A = 0
2. A^0 = A
When we take XOR of all numbers, the numbers repeating even number of times will results to 0 and the XOR of 0 with the number repeating odd number of times will give the number itself.
Check the Best Solutions
Submit your solution
You need to be logged in to submit a solution.
|jaydev13||name of input and output file|
|Q:||the name of the input and output file will be given by us or it will be a console I/P and output|
|A:||It will be console input and output|
|Q:||why this make compilation error?whether i have to write include files or not?|
|A:||You can't include the header files.|
|Mounika||Odd one out|
|Q:||Hi,In the Trail 2 question.Is the odd one repeated only once,or can it be 3 times.Something like this 1 2 1 2 3 3 3Because the inputs have the odd integer being repeated only once.That might simplify my solution.Thank you|
|A:||The odd one can be repeated more than once and so can the even one.|
post a question