Trains the technique from
LeetCode 867Transpose 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 logging rig writes its readings into matrix, a rectangle with one row per sensor and one column per sample instant.
The analysis stage wants the same readings laid out the other way round: one row per sample instant and one column per sensor. Mirror the rectangle across the line running from its top-left corner down and to the right, so the reading stored at row r, column c ends up at row c, column r.
Return the mirrored rectangle.
Example 1
The rig had two sensors and three sample instants, so the answer has three rows of two readings. The reading 6 sat at row 0, column 2 and now sits at row 2, column 0.
Example 2
Three sensors sampled once each. Mirroring turns the single column into a single row.
Example 3
The two readings on the mirror line, 2 and 3, stay where they are, and 6 and 8 trade places.
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 transpose(matrix: list[list[int]]) -> list[list[int]]:public int[][] transpose(int[][] matrix)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.