Pancake sort
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.
Implement
pancake_sort(arr: list[int]) → list[int]Examples
in
[[3,2,4,1]]out[3,4,2,3,2]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[3,2,4,1]][3,4,2,3,2]not run yetsample