title: How to remove only one max (min) from a list using Java 8 stream API in O(N) time and O(C) space complexity
body: <p>Here is a code for removing only one of the max values (in this case the first one, but this is irrelevant) from the list. It is <code>O(n)</code> in time and <code>O(n)</code> in space (beyond the input). </p>
  
  <pre><code>public List&lt;Integer&gt; removeOneOfTheMax(List&lt;Integer&gt; nums) {
      int max = Integer.MIN_VALUE;
      int maxIndex = -1;
      Iterator&lt;Integer&gt; it = nums.iterator();
      for (int i = 0; it.hasNext(); i++) {
          Integer temp = it.next();
          if (max &lt; temp) {
              maxIndex = i;
              max = temp;
          }
  
      }
      nums.remove(maxIndex);
      return nums;
  }
  </code></pre>
  
  <p><strong>1.</strong> What would be the equivalent of the method using the Java 8 stream API? I would like to preserve the time and space complexity, so no sorting is allowed.</p>
  
  <p><strong>2.</strong> Actually, if you pass a <code>LinkedList</code> into the above code the space complexity would be <code>O(C)</code> (again, beyond the input), but as far as I understand the <code>.stream()</code> creates an additional data structure so a stream API equivalent must be at least <code>O(N)</code> in space. Correct me if I am wrong.</p>