I am not able to understand the output what are we supposed to print in the answer
Doubt in the sample output
Input: [3,2,4,1]
Pick highest element so far. Do swaps to bring it to last position.
In the input ,4 is the highest. So subarray from 3 to 4 is reversed.
Swap 1: 4 2 3 1
The whole array is then reversed such that 4 reaches its desired position.
Swap 2: 1 3 2 4
Now the unsorted window is from index 0 to 2.Highest element in this window is 3.So subarray 1 3 is reversed
Swap 3: 3 1 2 4
Swap the whole window such that 3 reaches its desired position.
Swap 4: 2 1 3 4
Now the unsorted window is from index 0 to 1. Highest element in this window is 2.
Swap 5:1 2 3 4
Code and submit with the same approach on https://leetcode.com/problems/pancake-sorting/ to check.
There are test case issues with this question.
Let me know if your approach gives wrong answer even on Leetcode
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.