forked from sonumahajan/All_Program_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumMissingElement.cpp
More file actions
46 lines (46 loc) · 816 Bytes
/
MinimumMissingElement.cpp
File metadata and controls
46 lines (46 loc) · 816 Bytes
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
// Given a array, find the smallest missing positive number.
// Time Complexity -- O(n)
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter no. of elements in Array : ";
cin>>n;
int a[n];
cout<<"Enter Array Elements : ";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
bool ch[n];
for(int i=0;i<n;i++)
{
ch[i]=false;
}
for(int i=0;i<n;i++)
{
if(a[i]>=0 && a[i]<n)
{
ch[a[i]]=true;
}
}
int flag=-1;
for(int i=0;i<n;i++)
{
if(ch[i]==false)
{
flag=i;
break;
}
}
if(flag==-1)
{
cout<<"Minumum Missing Positive Element : "<<n;
}
else
{
cout<<"Minumum Missing Element : "<<flag;
}
return 0;
}