Check out example codes for "first missing number leetcode". It will help you in understanding the concepts better.

Code Example 1

int firstMissingPositive(vector<int>& nums) 
    {
        for(int i=0;i<nums.size();i++)
            while(nums[i]>0 && nums[i]<=nums.size() && nums[nums[i]-1]!=nums[i])
                swap(nums[i],nums[nums[i]-1]);
        
        for(int i=0;i<nums.size();i++)
            if(i+1!=nums[i])
                return i+1;
        
        return nums.size()+1;
    }

Learn ReactJs, React Native from akashmittal.com