public static int[] lexiographicPermute(int[] S, Permutator permutator) {
    // Find the position where lexiographic order
    // is not true
    int i = S.length - 2;
    while (i >= 0 && S[i] >= S[i + 1]) {