Tricky permutations


please check this code, three of my test case are not working and also i’m not able able to understand the editorial.