Given an array of integers, find the first missing positive integer in linear time and constant space
问题 In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. This question was asked by Stripe in it's programming interview. I have devised a solution for the same as below: #include<bits/stdc++.h> using namespace std; int main(){ int arr[]={1,-1,-5,-3,3,4,2,8}; int size= sizeof(arr)/sizeof(arr[0]); sort(arr, arr+size); int min=1; for(int i=0; i<size; i++){ if(arr[i]>min) break; if(arr[i]==min) min=min+1; }