626. Reveal Cards in Increasing Order

MediumStackQueueSimulation

Given a deck of distinct integers, arrange it so that repeatedly revealing the top card and moving the next card to the bottom yields the cards in increasing order. Return that arrangement. The input is JSON {deck}.

Input: JSON {deck}.

Output: Array — the ordered deck.

Examples

Example 1
Input: {"deck":[17,13,11,2,3,5,7]}
Output: [2,13,3,11,5,17,7]
Explanation: Reveals in increasing order.
Example 2
Input: {"deck":[1,1000]}
Output: [1,1000]
Explanation: Two cards.
Example 3
Input: {"deck":[5]}
Output: [5]
Explanation: Single card.

Constraints

Asked by

GoogleAmazonBloombergMicrosoft
Solve this problem in the editor →