C++ solution passing all cases in O(n)


#1

`int Solution::firstMissingPositive(vector &a) {

int n = a.size();
int i,mx=1,mn=1;

for(i=0;i<n;i++)
{
    if(a[i]>=0)
        mn=min(mn,a[i]);
    mx=max(mx,a[i]);
}

vector<int>v(mx+1,-1);


for(i=0;i<n;i++)
{
    if(a[i]>0)
      v[a[i]]=0;
}


for(i=1;i<=mx;i++)
{
    if(v[i]==-1)
      return i;
}


return mx+1;

}
`