Trains the technique from
LeetCode 2161Partition Array According to Given PivotThis 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 calibration run leaves you with a list of signed drift readings, one per probe, in the order the probes were sampled. One of the sampled values is singled out as the reference.
Rearrange the readings into a new list so that:
reference comes before every reading equal to reference;reference comes before every reading larger than reference;reference keep the order they had in the input, and two readings that are both larger than reference also keep the order they had in the input.Return the rearranged list. Exactly one list satisfies all three rules, so the answer is unique.
Example 1
The readings smaller than `5` are `2` and `1`, read in that order, and they open the list. The two readings equal to `5` follow. The readings larger than `5` are `8` and `7`, read in that order, and they close the list.
Example 2
Nothing is larger than `2`, so the list is just the two smaller readings `-5` and `-9` in their sampled order, followed by the two readings equal to `2`.
Example 3
No reading is smaller than `-4`, so the three readings equal to `-4` come first. The four larger readings keep their sampled order `0`, `6`, `6`, `0`.
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 reorder_readings(readings: list[int], reference: int) -> list[int]:public int[] reorderReadings(int[] readings, int reference)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.