forked from ThangaAyyanar/newapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind_unique.c
60 lines (48 loc) · 1.54 KB
/
Find_unique.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Non-Repeating Number Position
2N+1 numbers are passed as input to the program. Out of these numbers, N numbers repeat twice and hence account for 2N numbers. Only one number I is a non-repeating number. The program must print the position of the non-repeating number (The position starts from 1).
Note: You need to optimize the logic for large input values. Else "Timeout" will occur.
Input Format:
First line contains N.
Second line contains 2N+1 numbers separated by a space.
Output Format:
First line contains the position of the only non-repeating number I.
Boundary Conditions:
1 <= N <= 1000000
1 <= Value of an individual number <= 9999999
Example Input/Output 1:
Input:
10
86 11 40 10 78 63 73 68 16 44 86 11 40 10 78 73 68 16 24 44 24
Output:
6
Explanation:
N=10, Hence 21 numbers are passed as the input. Among these numbers, only 63 is not repeated. The position of 63 is 6 (As it occurs as the sixth number)
Example Input/Output 2:
Input:
12
7514716 2638298 6854805 6770589 1632983 6032326 6854805 2312182 2312182 367141 9985662 4682266 4682266 6770589 8713485 8964136 8964136 367141 9985662 3099970 1632983 3099970 6032326 8713485 2638298
Output:
1
Explanation:
The only non repeating number is 7514716 which is in the first position.
*/
#include<stdio.h>
int main(){
int n,unique;
scanf("%d",&n);
n=2*n+1;
int i,a[n];
scanf("%d",&a[0]);
unique=a[0];
for(i=1;i<n;i++){
scanf("%d",&a[i]);
unique=unique^a[i];//xor of same number 5^5=>0 hence find unique
}
for(i=0;i<n;i++){
if(a[i]==unique){
printf("%d",i+1);
}
}
return 0;
}