Why is this code not working for Leetcode Pancake Sorting Problem?

Why is this code not working for Leetcode Pancake Sorting Problem?

the logic that you are applying is correct but what you have assumed is the array would be a permutattion. Which is wrong. So, first sort the array, then look for elements in descending order.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.