Crossing blocks problem: Unable to find error in my submission

Hi there, I’ve been trying to figure out some error in my code but I am missing out on something:
you can view my submission here: Solution: 50314934 | CodeChef
The question: Contest Page | CodeChef

approach:
I am reversing the array to find the next greater element on right, then I run through the NGE jumping from one NGE to another in the array while keeping track of jumps using the following snippet. I also kept track of multiple occurrences of the max value elements as well.

while (i < n){
        
       // cout << i <<"->" << nge[i] << "\n";
        i = nge[i];
        count++;
    }

Only 3 test cases passed. Any help would be appreciated! Thanks!

1
6
5 4 5 4 5 4

Yours : 3
Correct : 2
1st Jump : 0th to 4th
2nd Jump : 4th to 5th

1 Like

@thunderboltz Thanks man for point out.

thanks bro