Pancake sort
Your task
You may sort an array only by 'pancake flips': choosing an index k and reversing the prefix arr[0..k-1] (the first k elements). Return any sequence of flip sizes k (each 1 <= k <= len(arr)) that, applied in order, sorts the array ascending. The given reference produces one valid canonical sequence by repeatedly bringing the current maximum to its final position. The array may contain duplicates and has length >= 1; return an empty list if it is already sorted by this procedure.
Examples
pancake_sort(arr: list[int]) -> list[int]Example 1
Input
pancake_sort([3, 2, 4, 1])Output
[3, 4, 2, 3, 2]