Trains the technique from
LeetCode 2974Minimum Number GameThis 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.
Two archivists, Ada and Ben, clear a pile of boxes. Each box carries a label, given as the list labels, and the pile holds an even number of boxes.
They repeat the following round until the pile is empty:
Labels may repeat; when two boxes carry the same label it makes no difference which of them is lifted, because the shelf reads the same either way.
Return the list of labels along the shelf, from the first box placed to the last.
Example 1
Round one: Ada lifts `4`, Ben lifts `9`, so the shelf starts `9`, `4`. Round two: Ada lifts `12`, Ben lifts `30`, so the shelf continues `30`, `12`.
Example 2
The first two rounds each lift a `6` and a `6`, and a `6` and an `8`; the last round lifts the remaining two `8`s. Placing each round's second box first gives the shelf shown.
Example 3
Ada lifts `1` and Ben lifts `2` in the first round, then Ada lifts `99` and Ben lifts `100`. Ben places before Ada each round.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def shelve_boxes(labels: list[int]) -> list[int]:public int[] shelveBoxes(int[] labels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.