Skip to main content
Back to problems
Leetcode
Medium
Arrays
Sorting
Queues
Stacks
Amazon
Reveal Cards In Increasing Order

Rearrange a deck so that repeatedly revealing the top card produces the cards in strictly increasing order.

Acceptance 0%
Problem Statement

Problem

You are given an array of unique integers representing a deck of cards. Your task is to reorder the deck so that if you perform the following process, the revealed cards appear in increasing order:

  1. Reveal the top card and remove it from the deck.
  2. If any cards remain, move the next top card to the bottom of the deck.
  3. Repeat until all cards are revealed.

Return one valid initial ordering of the deck that makes the revealed sequence sorted from smallest to largest.

Notes

  • The input values are distinct.
  • Any valid arrangement that satisfies the reveal process is acceptable.

Input Format

  • A single array of distinct integers deck.

The array represents the card values, not their initial positions.

Output Format

  • Return an array representing the initial deck order that causes the reveal process to output the cards in increasing order.

Constraints

  • 1 <= deck.length
  • All values in deck are distinct.
  • The answer should be a permutation of the input values.
Examples
Sample cases returned by the problem API.

Example 1

Input

deck = [17,13,11,2,3,5,7]

Output

[2,13,3,11,5,17,7]

Explanation

If you reveal from the top and move the next card to the bottom repeatedly, the revealed sequence is [2,3,5,7,11,13,17].

Example 2

Input

deck = [1,1000]

Output

[1,1000]

Explanation

The deck already reveals in increasing order.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.