Problem · Matrix
Rotate Matrix
Learn this problemProblem 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.
ᡣ𐭩 •Credit to Charlotte。ꪆৎ ˚⋅
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
- Collect CoinsSeen Jun 2025
- FizzBuzz ProblemSeen May 2025
- Find Largest Sum Contiguous SubarraySeen May 2025
- Find Largest Sum of Continuous SequenceSeen May 2025
- Find Palindrome Sub-stringSeen May 2025
- Count Numbers with Digit SumSeen Mar 2025
- Maximum Chocolates from Jars (L.C. 198 :)Seen Mar 2025
- Find Elements Largest in Row Smallest in ColumnSeen Mar 2025