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.
->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: https://www.codechef.com/viewsolution/36113085
Approach 2: According to the explanation in the Live session of Contest 2 (Part 2) given by @anon38711361(video link- https://www.youtube.com/watch?v=7Q2Nlf-fT4o&list=PLi0ZM-RCX5nsjTRrJVndL0jdJkIhKvGOJ&index=3 , 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: https://www.codechef.com/viewsolution/36113038
Can @anon38711361 or anyone please help me correct the error?