Write a Kotlin program to perform matrix multiplication.
MediumProblem Statement
Write a Kotlin program to perform matrix multiplication.
Sample Input
Matrix A = [[1, 2], [3, 4]], Matrix B = [[5, 6], [7, 8]]
Sample Output
19 22 43 50
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
fun multiplyMatrices(a: Array<Array<Int>>, b: Array<Array<Int>>): Array<Array<Int>> {
// Add your code here to multiply the matrices
}
fun main() {
val a = arrayOf(arrayOf(1, 2), arrayOf(3, 4))
val b = arrayOf(arrayOf(5, 6), arrayOf(7, 8))
val result = multiplyMatrices(a, b)
result.forEach { println(it.joinToString(" ")) }
}
Input
Matrix A = [[1, 2], [3, 4]], Matrix B = [[5, 6], [7, 8]]
Expected Output
19 22 43 50