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

Rotate a Square Matrix Clockwise

Visa logoVisa● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report keeps an N by N matrix and a clockwise rotation. Our version picks one 90-degree rotation that is returned. It leaves out a boundary side calculation whose result the report did not keep.

You are given an n x n integer matrix. Return a new matrix obtained by rotating the input exactly 90 degrees clockwise.

The returned cell at row r and column c must contain the original value from row n - 1 - c and column r. You do not need to mutate the input matrix.

Function

rotateSquareMatrixClockwise(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 becomes the first row in reverse order, and the same rule applies to every column.

Example 2

matrix = [[5]]return = [[5]]
matrix
005
→
return
005

A one-cell matrix is unchanged by rotation.

Example 3

matrix = [[-1,2],[3,4]]return = [[3,-1],[4,2]]
matrix
010-12134
→
return
0103-1142
Moved or new

The transformation preserves every signed value while moving it to its clockwise position.

Constraints

  • 1 <= n <= 500.
  • matrix.length = n and every row has length n.
  • Every matrix value is a signed 32-bit integer.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Maximum Diamond SumHudson River Trading · OAHudson River Trading interview questions
  • Robot Navigation Around LasersRoblox · OARoblox interview questions
  • Apply a Reversi MoveAmazon · OA
  • Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
  • Sparse Valid Conv2D From ScratchNVIDIA · OANVIDIA interview questions
  • Apply Matrix OperationsCapital One · OACapital One interview questions
  • Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
  • 2048 Move SimulatorBenchling · OABenchling interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int[][] rotateSquareMatrixClockwise(int[][] matrix) {
      // write your code here
    }
}
Checking account…