Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to transpose a matrix.

Hard

Problem Statement

Write a function to transpose a matrix.

Sample Input

A hardcoded matrix: 
[[1, 2, 3], 
[4, 5, 6], 
[7, 8, 9]]

Sample Output

1 4 7
2 5 8
3 6 9

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun transposeMatrix(matrix: Array<Array<Int>>): Array<Array<Int>> { // Add your code here to transpose the matrix } fun main() { val matrix = arrayOf( arrayOf(1, 2, 3), arrayOf(4, 5, 6), arrayOf(7, 8, 9) ) val transposed = transposeMatrix(matrix) transposed.forEach { println(it.joinToString(" ")) } }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded matrix: 
[[1, 2, 3], 
[4, 5, 6], 
[7, 8, 9]]
Expected Output
1 4 7
2 5 8
3 6 9