O(n) time and constant space


#1

/
int Solution::firstMissingPositive(vector &A) {
sort(A.begin(),A.end());
int i=0;
while(A[i]<=0){
i++;
}
int n=A.size();
int j=1;
while(i<n){
if(A[i]!=j)
return j;
i++;
j++;
}

}


#2

sort(A.begin(),A.end()); This takes nlogn time.