Reveal Cards in Increasing Order

Big-O & the Python Toolkit, problem 5 of 7

Reveal Cards in Increasing Order

Medium

LC #950

dequesimulationsorting

Not attempted yet

You have a deck of cards with distinct integers. Cards are revealed with this routine, starting from the top:

  1. Reveal the top card and remove it.
  2. If cards remain, move the new top card to the bottom.
  3. Repeat until the deck is empty.

Return an ordering of the deck (top card first) so the cards are revealed in increasing order.

Example 1

Input: deck = [4, 1, 3, 2]
Output: [1, 3, 2, 4]

Reveal 1, tuck 3 → [2, 4, 3]. Reveal 2, tuck 4 → [3, 4]. Reveal 3, tuck 4 → [4]. Reveal 4.

Example 2

Input: deck = [1000, 1]
Output: [1, 1000]

Example 3

Input: deck = [6, 5, 4, 3, 2, 1]
Output: [1, 4, 2, 6, 3, 5]

Constraints

  • 1 ≤ deck.length ≤ 10⁵
  • All values are distinct.

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.