Rotate Matrix
Updated
Problem statement
You are given a square matrix matrix with n rows and n columns. Rotate it by 90 degrees clockwise and return the rotated matrix.
After the rotation, the first column of the original matrix, read from the bottom up, becomes the first row; the second column, read from the bottom up, becomes the second row; and so on.
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]]Moved or new
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
1 ≤ matrix.length ≤ 50matrix[i].length == matrix.length(the matrix is square)-1000 ≤ matrix[i][j] ≤ 1000
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Survey Table: Group Given an AnswerSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Remaining Drone PowerAkuna Capital · OAAkuna Capital interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Query a Header-Encoded MatrixNVIDIA · OANVIDIA interview questions
- Squared Frobenius Norm of a Reflect-and-Stretch MapWalleye Capital · OA
- Invert or Blur an ImageOpenAI · OAOpenAI interview questions
- Count Pieces After Othello MovesHudson River Trading · OAHudson River Trading interview questions
- Trapped Characters in a GridAdobe · OAAdobe interview questions
- Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions
- Connected GroupsVisa · OAVisa interview questions