I am trying to solve 1000 pt problem and I have doubt about the sample case:
{2, 7, 3, 0, 6, 4, 5, 1} Returns: {1, 7, 3, 0, 6, 2, 5, 4 }
But when I manually solved it, I found a better permutation {1,7,3,0,2,4,5,6}. So is the problem correct? Any one can help?
"If there are several such permutations Q, return the one among them that has the lexicographically smallest child array."
If I don't miss something, your answer's child array is {0, 1, 7, 6, 5, 4, 2, 3} and their answer's child array is {0, 1, 7, 4, 6, 5, 2, 3}, which is lexicographically smaller than yours.
Oh, yes I misunderstood that part, thank you :)