code: private static void selectAllInPlace(
        int[] allRequired, int requiredFrom, int requiredTo, double[] array, int from, int to) {
      // Choose the first selection to do...
      int requiredChosen = chooseNextSelection(allRequired, requiredFrom, requiredTo, from, to);
      int required = allRequired[requiredChosen];
  
      // ...do the first selection...
      selectInPlace(required, array, from, to);
  
      // ...then recursively perform the selections in the range below...
      int requiredBelow = requiredChosen - 1;
      while (requiredBelow >= requiredFrom && allRequired[requiredBelow] == required) {
        requiredBelow--; // skip duplicates of required in the range below
      }
      if (requiredBelow >= requiredFrom) {
        selectAllInPlace(allRequired, requiredFrom, requiredBelow, array, from, required - 1);
      }
  
      // ...and then recursively perform the selections in the range above.
      int requiredAbove = requiredChosen + 1;
      while (requiredAbove <= requiredTo && allRequired[requiredAbove] == required) {
        requiredAbove++; // skip duplicates of required in the range above
      }
      if (requiredAbove <= requiredTo) {
        selectAllInPlace(allRequired, requiredAbove, requiredTo, array, required + 1, to);
      }
    }
docs: Performs an in-place selection, like {@link #selectInPlace}, to select all the indexes {@code
  allRequired[i]} for {@code i} in the range [{@code requiredFrom}, {@code requiredTo}]. These
  indexes must be sorted in the array and must all be in the range [{@code from}, {@code to}].