Kotlinlearncs.online LogoJava
Return to List

Solve: Array Transpose

Created By: Pranav Narayanan
/ Version: 2024.10.0

Write a function transpose that takes a rectangular Array<IntArray> matrix and returns its transpose.

The transpose of any matrix satisfies two properties. First, if the original matrix has m rows and n columns, the transpose has n rows and m columns. Second, if an element is in row i and column j in the original matrix, that element is in row j and column i in the transpose. For example:

| 1 2 3 |  should become  | 1 4 |
| 4 5 6 |                 | 2 5 |
                          | 3 6 |

The passed array is always rectangular. If the passed array is empty (0 rows or 0 columns), you should return an array with 0 rows.

Related Lessons

Stuck? You may find these lessons helpful:

Report a Problem

Attribution must link to this page: https://www.learncs.online/solve/kotlin/array-transpose/[email protected]