pancakesort sorting a given array mutation of selection sort reference https www geeksforgeeks orgpancakesorting overall time complexity on2 finding index of maximum number in arr needs moving reverse from 0 to indexmax reverse list pancake_sort sorting a given array mutation of selection sort reference https www geeksforgeeks org pancake sorting overall time complexity o n 2 finding index of maximum number in arr needs moving reverse from 0 to index_max reverse list
def pancake_sort(arr):
    

    len_arr = len(arr)
    if len_arr <= 1:
        return arr
    for cur in range(len(arr), 1, -1):
        
        index_max = arr.index(max(arr[0:cur]))
        if index_max+1 != cur:
            
            if index_max != 0:
                
                arr[:index_max+1] = reversed(arr[:index_max+1])
            
            arr[:cur] = reversed(arr[:cur])
    return arr