#include <bits/stdc++.h>
int firstMissing(int arr[], int n)
{
for(int i=0;i<n;i++){
while (arr[i] > 0 && arr[i]<=n && arr[arr[i] - 1] != arr[i]) {
int temp = arr[i];
arr[i] = arr[temp - 1];
arr[temp - 1] = temp;
}
}
for (int i=0; i<n; ++i) {
if (arr[i]!=i+1) {
return i+1;
}
}
return n+1;
}
int main() {
int arr[] = {3, 2, -6, 1, 0};
int n = sizeof(arr) / sizeof(arr[0]);
std::cout << "The first missing positive integer is: " << firstMissing(arr, n) << std::endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+IAppbnQgZmlyc3RNaXNzaW5nKGludCBhcnJbXSwgaW50IG4pCnsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICAgIHdoaWxlIChhcnJbaV0gPiAwICYmIGFycltpXTw9biAmJiBhcnJbYXJyW2ldIC0gMV0gIT0gYXJyW2ldKSB7CiAgICAgICAgICAgIGludCB0ZW1wID0gYXJyW2ldOwogICAgICAgICAgICBhcnJbaV0gPSBhcnJbdGVtcCAtIDFdOwogICAgICAgICAgICBhcnJbdGVtcCAtIDFdID0gdGVtcDsKICAgICAgICB9CiAgICB9CgogICAgZm9yIChpbnQgaT0wOyBpPG47ICsraSkgewogICAgICAgIGlmIChhcnJbaV0hPWkrMSkgewogICAgICAgICAgICByZXR1cm4gaSsxOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gbisxOyAKfQppbnQgbWFpbigpIHsKCWludCBhcnJbXSA9IHszLCAyLCAtNiwgMSwgMH07CgkgICAgaW50IG4gPSBzaXplb2YoYXJyKSAvIHNpemVvZihhcnJbMF0pOwoJICAgIHN0ZDo6Y291dCA8PCAiVGhlIGZpcnN0IG1pc3NpbmcgcG9zaXRpdmUgaW50ZWdlciBpczogIiA8PCBmaXJzdE1pc3NpbmcoYXJyLCBuKSA8PCBzdGQ6OmVuZGw7CgkgICAgcmV0dXJuIDA7Cgl9