FastPrepRotate a Rectangular Matrix Clockwise
Problems/Rotate a Rectangular Matrix Clockwise

Rotate a Rectangular Matrix Clockwise

Google logoGoogle● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for a 90-degree rotation of any n-by-m matrix, notes that n need not equal m, and asks about O(1) space and a closed-form solution. Clockwise follows the well-known matrix rotation problem and the author's confirmed generalization. We chose the return encoding, examples, input limits, and that the output storage does not count toward extra space. Our version is about 95% the same as the reported question.

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]]
matrix
01201231456
→
return
01041152263

The two rows become the two columns read from bottom to top.

Example 2

matrix = [[1],[2],[3]]return = [[3,2,1]]
matrix
0011223
→
return
0120321

A 3x1 column becomes a 1x3 row.

Example 3

matrix = [[7,8,9,10]]return = [[7],[8],[9],[10]]
matrix
0123078910
→
return
0071829310

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

Interview reports that mention this question

  • Google New Grad SDE R1 and NYC Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] rotateRectangularMatrix(int[][] matrix) {
        // write your code here
    }
}
Checking account…