Trains the technique from
LeetCode 498Diagonal TraverseThis 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 rig stores its readings in a grid plate with m rows and n columns, where plate[i][j] is a signed offset in micrometres and may be negative.
The rig's arm does not read row by row. It groups the cells into sweeps: two cells belong to the same sweep when their row index and column index add up to the same total. The arm works through the sweeps in increasing order of that total, starting with the sweep whose total is 0.
Inside a sweep the arm alternates which way it travels. When the sweep's total is even, the arm reports its cells starting from the largest row index and working down to the smallest. When the total is odd, it reports them from the smallest row index up to the largest.
Return the offsets in the order the arm reports them.
Example 1
Sweep 0 holds only -4. Sweep 1 has an odd total so it runs downward through 7 then 5. Sweep 2 is even and runs upward through -1 then 2, and sweep 3 finishes with 9.
Example 2
With a single column every sweep holds exactly one cell, so the direction never matters and the column is read top to bottom.
Example 3
A single row also puts one cell in each sweep, so the readings come out left to right.
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 slanted_sweep_readout(plate: list[list[int]]) -> list[int]:public int[] slantedSweepReadout(int[][] plate)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.