Siddharth and Permutations

please provide solution editorial for this problem!

HINT: its about giving priorities , first -1 should be given the highest number which is not there in the array , because right of it all should be small, try with topological sorting.