Problem statement
Given a grid, exchange its rows and columns, so the value at row r, column c moves to row c, column r.
A square grid has to be handled in place. A rectangle cannot be, because its destination cells are outside it.
Examples
Inputm = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
Only the three cells above the diagonal move, each swapping with its partner below.
Inputm = [[1, 2, 3, 4], [5, 6, 7, 8]]
Output[[1, 5], [2, 6], [3, 7], [4, 8]]
The grid changes shape from two by four to four by two, so a second grid is required.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing