GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesPancake Flipper

Gamified challenge · Greedy placement

Pancake Flipper

stack[0] is the size of the top pancake and stack[n − 1] the bottom one. A flip `k` slides the spatula under the k-th pancake from the top and turns the top k over, reversing their order: flip 3 on [3, 2, 4, 1] gives [4, 2, 3, 1].

Write flips(stack) that returns a list of flip sizes (each from 1 to n) that leaves the stack sorted smallest on top (each pancake no bigger than the one below it), using at most `2n` flips. Any such list is accepted; an already sorted stack can return [].

For [3, 2, 4, 1], one answer is [3, 4, 2, 3, 2]: [4, 2, 3, 1] → [1, 3, 2, 4] → [3, 1, 2, 4] → [2, 1, 3, 4] → [1, 2, 3, 4].

Sign in to play Pancake Flipper

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account