FastPrepRotate Image
Problems/Rotate Image

Rotate Image

SambaNova Systems logoSambaNova Systems● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two firsthand SambaNova phone interview reports clearly describe the well-known Rotate Image problem. One asks for a solution that does not use a transpose helper.

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 SambaNova Systems Phone Screen questions

  • Deterministic Zigzag SortPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Minimum Window SubstringPHONE SCREEN · Seen Jun 2022
  • Number of ProvincesPHONE SCREEN · Seen Jun 2022
  • Merge Three Sorted ArraysPHONE SCREEN · Seen Jun 2022
  • Task Scheduler with CooldownPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Point Inside a TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Parse Variable, Expression, and Application TreesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Decode StringPHONE SCREEN · Seen Mar 2022
  • Insert, Delete, and Get Random in Constant TimePHONE SCREEN · Seen Mar 2022
  • Ugly NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2021

Similar questions at other companies

  • Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
  • Linear, Sigmoid and L2 Forward and Backward PassesNVIDIA · PHONE SCREENNVIDIA interview questions
  • Rotate ImageTokopedia · PHONE SCREENTokopedia interview questions
  • Scaled Dot-Product AttentionAmazon · PHONE SCREEN
  • Multiply Two MatricesAdobe · PHONE SCREENAdobe interview questions
  • Adjacent Order-Statistic Gap DistributionsScale AI · PHONE SCREENScale AI interview questions
  • Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Linear Layer Forward and Backward PassesMeta · ONSITE INTERVIEWMeta interview questions
  • Build a Gaussian Blur KernelLuma AI · OALuma AI interview questions
  • Rotate a Square Grid ClockwiseC3.ai · ONSITE INTERVIEWC3.ai interview questions
All SambaNova Systems interview questionsSee SambaNova Systems hiring insights
Saved
class Solution {
    public int[][] rotateImage(int[][] matrix) {
        // Rotate matrix in place, then return it.
    }
}
Checking account…