Getting WA in "Chefs in Queue"

Hey folks,
I tried to solve the above problem using stack with two different approaches but getting an WA. I have tried various corner test cases but in vain. Please help me find out the error.
Approach 1:
->Traversed the array from right towards left.
->Pushed the array element into the stack if it is empty
->while the stack is not empty and its top element is greater than or equal to the current array element, pop the stack top
->If the stack is not empty and its top is less than current array element, this is the required chef junior to the current chef. While loop breaks and chaos is calculated. Otherwise if the stack is empty, there is no junior chef.
-> The current element is pushed on to the stack.

Link to the above submission:

Approach 2: According to the explanation in the Live session of Contest 2 (Part 2) given by @anon38711361(video link- , Timestamp- 1:42:24), I tried to implement the exact solution. But still getting a WA (Not even a single test case is getting accepted).

Link to the above submission:

Can @anon38711361 or anyone please help me correct the error?

we need to start from the end of the queue(means start of the array), but u r starting from the end of the array.

Your implementation is also a bit weird . I suggest u to read this article properly. :slight_smile:

You can refer my code :