Trains the technique from
LeetCode 54Spiral MatrixThis 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 thermal camera keeps a per-pixel calibration offset for every cell of its sensor, stored as a grid panel of m rows and n columns. Offsets may be negative, since a pixel can read cold as well as hot.
The firmware ships these offsets over a serial link on an inward clockwise track. Starting at the top-left cell it sweeps the first row rightwards, drops down the final column, sweeps the last row back to the left, climbs the first column, and then applies the same track to the rectangle still untouched inside. It stops once every cell has gone out on the wire.
Return the offsets in the exact order the firmware ships them.
Example 1
The outer ring goes out first, ending at the offset 0 on the left edge, and the lone inner cell 7 is shipped last.
Example 2
After the outer ring, the leftover rectangle is the single row `[0, -8]`, which is swept rightwards.
Example 3
A one-column sensor gives a track that only ever heads downwards.
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 readout_order(panel: list[list[int]]) -> list[int]:public List<Integer> readoutOrder(int[][] panel)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.