</> MAANG.io
coding interview Β· 101

Foundations

Master coding interviews with comprehensive coverage of data structures, algorithms, and problem-solving techniques. Progress from fundamentals to advanced topics with expertly curated content.

0/255 solved 0% complete

Reveal Cards In Increasing Order

Core idea: The reveal rule (take top, then move the next card to the bottom) is fixed and deterministic. Don't guess the starting order β€” let an empty-slot queue deal the already-sorted cards into their final homes, replaying the exact rule. One sort + one queue pass gives the arrangement.


1. The problem, in a fresh setting

You're building a deterministic dealer for an online card game. The client reveals a deck by a fixed ritual: reveal the top card, then move the new top card to the bottom, repeat until the deck is empty. You want the revealed cards to come out in strictly increasing order β€” so you must hand the client the initial stacking that makes the ritual produce a sorted reveal.

Given a deck of distinct integers, return an ordering of them so that applying the reveal ritual yields them in increasing order.

deck (any order) One valid initial stacking (top→bottom) Reveal ritual yields
[8, 2, 5, 1, 3] [1, 8, 2, 5, 3] 1, 2, 3, 5, 8 βœ“
[1, 2] [1, 2] 1, 2 βœ“
[7] [7] 7 βœ“

The values are whatever you're given; what you control is their order in the returned deck.


Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account β€” no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.