FastPrepRotate Matrix

Rotate Matrix

Cisco logoCisco● EasyINTERNOA
Learn

Problem statement

You are given a matrix of N*M size. Write an algorithm to rotate the matrix by 90 degrees.

Input

The first line of input consists of two integer- inputMat_row and inputMat_col, representing the number of row (N) and column (M) of the matrix. The next M lines consist of N space-separated integers representing the elements of the matrix.

Output

Print the matrix after rotating it by 90 degrees.

Note

Number of rows (N) and number of columns (M) will always be same.

Function

rotateMatrix(matrix: int[][]) → int[][]

Examples

Example 1

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]return = [[7, 4, 1], [8, 5, 2], [9, 6, 3]]

We have to rotate the given matrix by 90 degrees, so we will rotate each and every element of the matrix in clockwise direction, and we get "7 4 1", "8 5 2", "9 6 3" in each row.

Constraints

  • 🍉🍉

More Cisco problems

See Cisco hiring insights
public int[][] rotateMatrix(int[][] matrix) {
 // write your code here
    
}
matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
expected[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
Checking account…