Element appearing once

 Element appearing once 

Given an sorted array A[i] of positive integers having all the numbers occuring exactly twice, except for one number which will occur only once. Find the number occuring only once.

Input
The first line of input contains an integer T denoting the number of test cases. Then T test cases
follow. The first line of each test case contains a positive integer N, denoting the size of the array.
The second line of each test case contains a positive integers, denoting the elements of the
array.


Output
Print out the singly occuring number.


Constraints
1 <= T  <= 100
0 <   N  <= 100
0 <= A[i] <= 100

Examples 

Input
2
5
1 1 2 5 5
7
2 2 5 5 20 30 30


Output
2
20

 

Expected Complexity

Time : O(N)


SOLUTION:

t=int(input())

for i in range (t):

    n=int(input())

    p=list(map(int,input().split()))

    for i in p:

        if(p.count(i)==1):

            print(i)

            break

Comments

Popular posts from this blog

Short Notes Of computer Network

Short Note of Data Structure

Implement stack using array