Rearrange a deck so that repeatedly revealing the top card produces the cards in strictly increasing order.
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:
Return one valid initial ordering of the deck that makes the revealed sequence sorted from smallest to largest.
deck.The array represents the card values, not their initial positions.
1 <= deck.lengthdeck are distinct.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
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.