Reveal Cards in Increasing Order
Medium
LC #950
dequesimulationsortingNot attempted yet
You have a deck of cards with distinct integers. Cards are revealed with this routine, starting from the top:
- Reveal the top card and remove it.
- If cards remain, move the new top card to the bottom.
- 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.