Find the first missing positive integer in an array of integers The problem is the one explained in Given an unsorted integer array, find the first missing positive integer


  Given an unsorted integer array, find the first missing positive
  integer.
  
  For example,
  Given [1,2,0] return 3,
  and [3,4,-1,1] return 2.
  
  Your algorithm should run in \$O(n)\$ time and use constant space.


I am trying to learn Java 8+ and wrote the following code. Request any improvisations possible.

int firstPositive(int[] inputArray) {

    //Convert all negative numbers to 0.
    IntStream.range(0, inputArray.length).forEach(idx -&gt; {
        if (inputArray[idx] &lt; 0) inputArray[idx] = 0;
    });

    IntStream.range(0, inputArray.length).forEach(idx -&gt; {
        if (Math.abs(inputArray[idx]) == 0) {
            inputArray[0] = -Math.abs(inputArray[0]);
        }
        else if (Math.abs(inputArray[idx]) - 1 &lt; inputArray.length &amp;&amp; inputArray[Math.abs(inputArray[idx]) - 1] &gt; 0) {
            inputArray[Math.abs(inputArray[idx]) - 1] *= -1;
        }
    });

    OptionalInt res = IntStream.range(0, inputArray.length).filter(idx -&gt; inputArray[idx] &gt;= 0).findFirst();

    if (res.isPresent()) {
        return res.getAsInt()+1;
    }

    return inputArray.length+1;
}
Instead of 

if (res.isPresent()) {
    return res.getAsInt()+1;
}

return inputArray.length+1;


you could make use of the orElse method of OptionalInt:

return res.orElse(inputArray.length) + 1;