All problems
1137MediumArrayQueueSortingSimulation

Stacking the Tags to Deal Them in Order

Tracked in this browser only
Write code

Trains the technique from

LeetCode 950Reveal Cards In Increasing Order

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def deck_revealed_increasing(tags: list[int]) -> list[int]:
Java
public int[] deckRevealedIncreasing(int[] tags)
September 7
Apply