code: private static void checkSorted(int[] sorted) {
      for (int i = 0; i < sorted.length-1; i++) {
        if (sorted[i] > sorted[i+1]) {
          throw new RuntimeException("input must be sorted!");
        }
      }
    }
docs: Parameter validity check.