Skip to content

Commit 0372799

Browse files
Added soln
1 parent d049761 commit 0372799

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
//Position this line where user code will be pasted.
4+
int missingNumber(int arr[], int n);
5+
int main() {
6+
int t;
7+
cin>>t;
8+
while(t--){
9+
int n;
10+
cin>>n;
11+
int arr[n];
12+
for(int i=0; i<n; i++)cin>>arr[i];
13+
cout<<missingNumber(arr, n)<<endl;
14+
}
15+
return 0;
16+
}
17+
int missingNumber(int arr[], int n) {
18+
19+
// Your code here
20+
map<int,int>mp;
21+
for(int i=0;i<n;i++)
22+
if(arr[i]>0)
23+
mp[arr[i]]++;
24+
25+
map<int, int>:: iterator it;
26+
int max_ele = *max_element(arr,arr+n);
27+
int i=1;
28+
while(i<=max_ele)
29+
{
30+
if(mp.find(i)==mp.end())
31+
return i;
32+
i++;
33+
}
34+
return i;
35+
}

0 commit comments

Comments
 (0)