We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d049761 commit 0372799Copy full SHA for 0372799
smallest_positive_missing_integer.cpp
@@ -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
35
0 commit comments