Tap here to switch tabs
Problem
Submissions

Problem: Pancake Sorting

med
30 min
Try to solve the Pancake Sorting problem.

Statement

Given an array of integers arr, sort the array by performing a series of pancake flips.

In a single pancake flip, choose an integer k such that 1≤k≤1 \le k \le arr.length, and reverse the prefix containing the first k elements of arr.

Return a list of values of k corresponding to a sequence of pancake flips that sorts arr. Any valid sequence of pancake flips that sorts the array is acceptable.

Constraints:

  • 1≤1 \le arr.length ≤100\le 100

  • 1≤1 \le arr[i] ≤\le arr.length

  • All integers in arr are unique (that is, arr is a permutation of the integers from 11 to arr.length).

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Pancake Sorting

med
30 min
Try to solve the Pancake Sorting problem.

Statement

Given an array of integers arr, sort the array by performing a series of pancake flips.

In a single pancake flip, choose an integer k such that 1≤k≤1 \le k \le arr.length, and reverse the prefix containing the first k elements of arr.

Return a list of values of k corresponding to a sequence of pancake flips that sorts arr. Any valid sequence of pancake flips that sorts the array is acceptable.

Constraints:

  • 1≤1 \le arr.length ≤100\le 100

  • 1≤1 \le arr[i] ≤\le arr.length

  • All integers in arr are unique (that is, arr is a permutation of the integers from 11 to arr.length).