Description
Order a deck so that when revealed (take top card, put next card at bottom, repeat), cards appear in increasing order.
Examples
Input:
deck = [17,13,11,2,3,5,7]Output:
[2,13,3,11,5,17,7]Explanation:
Reveals in order: 2,3,5,7,11,13,17.
Input:
deck = [1]Output:
[1]Explanation:
Edge case with a single-element array.
Input:
deck = [4,8,6,2]Output:
[2,6,4,8]Explanation:
Sorting [4,8,6,2] to get [2,4,6,8]. Working backwards: start with empty queue, add 8 → [8], add 6 → move 8 to front, add 6 to front → [8,6], add 4 → move 6 to front, add 4 to front → [6,4,8], add 2 → move 8 to front, add 2 to front → [2,6,4,8]. Revealing: take 2, move 6 to back → [4,8,6], take 4, move 8 to back → [6,8], take 6, move 8 to back → [8], take 8. Result: 2,4,6,8 ✓
Constraints
- •
1 ≤ deck.length ≤ 1000