A data grid component has a "swap rows and columns" button. The table is table, an array of rows of equal length.
Write transpose(table) that returns a new table where row c holds what was column c: the cell at row r, column c moves to row c, column r.
Input: table = [[1,2,3],[4,5,6]] Output: [[1,4],[2,5],[3,6]]
The 2 by 3 table becomes 3 by 2: its first column 1, 4 is now the first row.
Input: table = [[7]] Output: [[7]]
A single cell stays put.
1 <= rows, cols <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #75 Transpose a Data Table. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.