FastPrepRotate a Square Matrix 90 Degrees Clockwise
Problems/Rotate a Square Matrix 90 Degrees Clockwise

Rotate a Square Matrix 90 Degrees Clockwise

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report explicitly names Rotate Image: rotate an n by n matrix 90 degrees clockwise in place. The report leaves out limits and a way to return the matrix, so our version supplies those details and keeps the in-place change.

You are given an n × n integer matrix that represents an image. Rotate the image by 90 degrees clockwise.

Do the rotation in place by changing matrix directly. Return that same matrix afterwards so the answer can be checked. In your final approach, do not create another n × n matrix.

Function

rotateImage(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]]
matrix
012012314562789
→
return
012074118522963
Moved or new

The first column, read from the bottom up, is seven, four, one. It becomes the first row. Every other column turns into a row in the same way.

Example 2

matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]return = [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
matrix
0123051911124810213367315141216
→
return
0123015132511434121268931671011
Moved or new

The first column, read from the bottom up, is fifteen, thirteen, two, five. It becomes the first row. Each column turns into a row, reading bottom to top.

Constraints

  • n == matrix.length == matrix[i].length.
  • 1 <= n <= 20.
  • -1000 <= matrix[i][j] <= 1000.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Build a Gaussian Blur KernelLuma AI · OALuma AI interview questions
  • Survey Table: Group Given an AnswerSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Linear Layer Forward and Backward PassesMeta · ONSITE INTERVIEWMeta interview questions
  • Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
  • Rotate a Square Grid ClockwiseC3.ai · ONSITE INTERVIEWC3.ai interview questions
  • Linear, Sigmoid and L2 Forward and Backward PassesNVIDIA · PHONE SCREENNVIDIA interview questions
  • Rotate ImageTokopedia · PHONE SCREENTokopedia interview questions
  • Rotate ImageSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
  • Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[][] rotateImage(int[][] matrix) {
        // Rotate matrix in place, then return it.
    }
}
Checking account…