2
def pancakeSort(self, arr: List[int]) -> List[int]:3
# helper function to flip the numbers in the array6
arr[i], arr[j] = arr[j], arr[i]12
# base case where all the numbers are sorted, thus no more recursive calls16
# find the biggest number, which always will be the len(arr), or i + 117
idx = arr.index(i + 1)18
# if the biggest number is in the right place, as in idx == i, then we don't change anything, but just move to sort the next biggest number22
# we flip it with the first element (even if the biggest number is the first element, it will flip itself (k = 1) and does not affect the result25
# we know the biggest number is the first element of the array. Flip the whole array in the boundary so that the biggest number would be in the last of the subarray (notice not len(arr) - 1 because that will flip the already-sorted elements as well)28
# sort the next biggest number by setting a new boundary i - 129
return ret + sort(i - 1)31
return sort(len(arr) - 1)