Introduction

Hello there! Are you ready to enhance your programming skills with an exciting exercise using Kotlin? In this unit, we are delving into the world of matrices. Specifically, we'll be transposing a given matrix. Let's dive into this matrix manipulation game without delay!

Task Statement

Let's dive into the task at hand. Your objective is to write a Kotlin function named transformMatrix(). This function will accept a 2D Int array (which represents a matrix) containing integers as input. Your responsibility is to return another 2D Int array, which is the transposed version of the given matrix.

Remember, transposing a matrix involves switching its rows and columns. In other words, all the rows of the original matrix should convert into columns in the transposed matrix, and vice versa.

For instance, if the original matrix (input 2D array) is:

Then the transposed matrix (output 2D array) will be:

It is crucial for your result to maintain the integrity of the data type in the original matrix. The values in the input matrix are integers, and they should remain integers in the output matrix as well.

Solution Building: Step 1

The initial step in building our solution involves determining the dimensions of the matrix. We need to know the number of rows and columns present in it. In Kotlin, the size properties can provide this information. The number of rows corresponds to the size of the outer array, and the number of columns matches the size of any inner array.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal