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.
Stuck? You may find these lessons helpful: