CHEF IN QUEUE DSA

https://www.codechef.com/viewsolution/32003457

what is wrong in the approach?

You didn’t understand the question clearly,
the question states that, suppose you have a junior in front of you, then you gave your bills to your junior and you moved out of the queue,
similarly, the seniors who were in queue if they have any juniors in front of him at any place, they give their bills(i.e. calculate indexes here) and remove that senior from that place.

1 Like

The logical flaw in this approach is in line 19.Instead of a[j]>a[i] it should be a[i]>a[j].
But then again you would get a TLE with a bruteforcing approach. Try using some DS like stack to make the operation efficient.

Now Understood thanks!!!

I’m also getting wrong answer.Could you please tell me what’s wrong in my code. or any test cases where my code is failing.

CodeChef: Practical coding for everyone.

Thanks.

Is there any editorial for this problem, i can only find hints