```
class Solution {
public:
int firstMissingPositive(vector<int>& nums) {
sort(nums.begin(),nums.end());
int n=nums.size(),first=1;
for(int i=0; i<n; i++) {
if (nums[i]==first) first++;
}
return first;
}
};
```

The Idea is to first sort the array to get the numbers in non-decreasing order. If we find the first positive value, `first`

(which is initially `1`

), we increment it and are searching for it next.

Last value of `first`

is the answer.