-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_repeating_number_in_array.cpp
More file actions
49 lines (38 loc) · 1.07 KB
/
first_repeating_number_in_array.cpp
File metadata and controls
49 lines (38 loc) · 1.07 KB
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
// program to return a first repeating element in an integer array
// code is written considering various test cases provided by the user
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
int n;
cin>>n;
int arr[n];
int f=0;
while(t--)
{
f=0;
for(int i=0 ; i<=n-1;i++)
{
cin>>arr[i];
}
for(int j=0 ; j<=n-1;j++)
{
for(int m=j+1;m<=n-1;m++)
{
if(arr[j]==arr[m])
{
f=1;
cout<<j<<endl;
break;
}
}
}
if(f==0)
{
cout<<"-1";
}
}
return 0;
}
// TIME COMPLEXITY OF THE CODE :::----- O(N^2) bigoh-nsquare ///not so efficient approach;/