WA in TRPLSRT

Continuing the discussion from TRPLSRT - Editorial:

Can someone help me out where my solution was wrong , I did by using map, Please help me out

Here is the link to my solution-CodeChef: Practical coding for everyone

I was also getting almost the same verdict. What I did was to change the while loop to for and then adding a while inside it and doing if else conditions. It worked out for me. Maybe you can get help from my solution. (Check on My Profile)

People who are looking for TRPLSRT test cases. Here is the list in which most of the types are covered:
// Test Case
9
4 2
3 2 4 1
4 2
2 1 4 3
4 2
1 2 3 4
3 2
3 1 2
3 2
3 2 1
4 2
4 3 2 1
4 1
2 1 4 3
8 3
1 3 2 6 4 5 8 7
2 1
1 2

// Expected Result
1
1 3 4
2
2 1 4
2 3 4
0
1
1 3 2
-1
2
4 1 3
4 2 3
-1
3
4 6 5
3 2 8
3 7 8
-1