Rotate a Rectangular Matrix Clockwise
Updated
Problem statement
Given a nonempty rectangular integer matrix with m rows and n columns, return its 90-degree clockwise rotation.
The returned matrix has n rows and m columns. Use only O(1) auxiliary space beyond the required output matrix.
Function
rotateRectangularMatrix(matrix: int[][]) → int[][]Examples
Example 1
matrix = [[1,2,3],[4,5,6]]return = [[4,1],[5,2],[6,3]]The two rows become the two columns read from bottom to top.
Example 2
matrix = [[1],[2],[3]]return = [[3,2,1]]A 3x1 column becomes a 1x3 row.
Example 3
matrix = [[7,8,9,10]]return = [[7],[8],[9],[10]]A 1x4 row becomes a 4x1 column.
Constraints
1 <= matrix.length, matrix[0].length <= 300.- Every row has the same length.
-1000000000 <= matrix[i][j] <= 1000000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Validate a Two-Color ChessboardAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
- Detect a Winner on a 3x3 Tic-Tac-Toe BoardHebbia · ONSITE INTERVIEW
- Trace of a Square MatrixAkuna Capital · PHONE SCREEN · ONSITE INTERVIEWAkuna Capital interview questions
- Unique Rows of a Binary MatrixExpedia · ONSITE INTERVIEWExpedia interview questions
- Iterate Ragged Integer Lists VerticallyZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Number of IslandsFleetx · ONSITE INTERVIEW
- Spiral MatrixAthenahealth · ONSITE INTERVIEW