Reveal Cards In Increasing Order
Real-world version: Stacking the Tags to Deal Them in OrderThe statement here is our own: the same inputs, outputs and technique.
A stack of tags is held face down and dealt like this, over and over until nothing is left:
- Take the tag at the top of the stack and set it aside.
- If any tags remain, move the tag now at the top to the bottom of the stack.
Return an arrangement of the very same tags, listed from top to bottom, whose dealing sets them aside in increasing order. Exactly one arrangement does that.
Examples
Example 1
- Input
- tags = [1, 2, 3, 4]
- Output
- [1, 3, 2, 4]
Dealing this arrangement sets aside 1, moves 3 to the bottom, sets aside 2, moves 4 to the bottom, sets aside 3 and finally sets aside 4.
Example 2
- Input
- tags = [5]
- Output
- [5]
One tag is set aside straight away with nothing to move.
Example 3
- Input
- tags = [2, 1]
- Output
- [1, 2]
The smaller tag goes on top and is set aside first, then the other is moved to the bottom and set aside next.
Constraints
- 1 <= tags.length <= 1000
- 1 <= tags[i] <= 10^6
- no two tags are the same
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def deck_revealed_increasing(tags: list[int]) -> list[int]:public int[] deckRevealedIncreasing(int[] tags)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Minimum Number GameReal-world version: Shelving Boxes in TurnsEasy
- Number of Students Unable to Eat LunchReal-world version: Stranded at the Battery SwapEasy
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy
- Find the Winner of the Circular GameReal-world version: Last Apprentice at the KilnMedium