Trains the technique from
LeetCode 75Sort ColorsThis 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 walk-in clinic gives every waiting patient a wrist band carrying one of three codes: 0 for immediate, 1 for urgent, 2 for routine. The array bands lists those codes in the order the patients arrived.
Rebuild the queue so that the codes climb: no immediate band may sit behind an urgent or routine band, and no urgent band may sit behind a routine band. Patients sharing a code are interchangeable, so their relative positions do not matter.
Work on bands itself and return it. Touch each position a bounded number of times in one sweep across the array, keep only a fixed set of extra variables, and do not hand the work to a sorting routine from your language's library.
Example 1
Two patients hold an immediate band, two hold urgent and two hold routine, so the queue settles into those three runs.
Example 2
The queue arrived in exactly the wrong order, so all three patients change position.
Example 3
Both bands carry the same code, so the queue already climbs and nothing moves.
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 order_bands(bands: list[int]) -> list[int]:public int[] orderBands(int[] bands)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.