FastPrepRotate Matrix Regions Around the Diagonals
Problems/Rotate Matrix Regions Around the Diagonals

Rotate Matrix Regions Around the Diagonals

Hudson River Trading logoHudson River Trading● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Hudson River Trading new grad online assessment. The report sums up how the coordinates change, but gives no limits or worked example. Our version is about 97% the same as the reported question.

You are given an n x n integer matrix and an integer turns. The main diagonal and anti-diagonal divide the remaining cells into top, right, bottom, and left regions.

One turn rotates those four regions clockwise by 90 degrees. Every non-diagonal value at (row, column) moves to (column, n - 1 - row), while every cell on either diagonal stays fixed.

Apply exactly turns turns and return the resulting matrix.

Function

rotateMatrixOverDiagonals(matrix: int[][], turns: int) → int[][]

Examples

Example 1

matrix = [[1,2,3,4,5],[2,1,9,6,3],[7,0,4,8,1],[5,2,4,1,9],[6,4,3,2,1]]turns = 1return = [[1,5,7,2,5],[4,1,0,6,2],[3,4,4,9,3],[2,2,8,1,4],[6,9,1,3,1]]
matrix
01234012345121963270481352419464321
→
return
01234015725141062234493322814469131
Moved or new

The diagonal values remain in place. Every other value advances clockwise into the next triangular region.

Example 2

matrix = [[1,2,3],[4,5,6],[7,8,9]]turns = 1return = [[1,4,3],[8,5,2],[7,6,9]]
matrix
012012314562789
→
return
012014318522769
Moved or new

The four off-diagonal values 2, 6, 8, and 4 move clockwise, while the five diagonal values stay fixed.

Example 3

matrix = [[7]]turns = 3return = [[7]]
matrix
007
→
return
007

The only cell lies on both diagonals, so every turn leaves it unchanged.

Constraints

  • 1 <= n <= 200.
  • matrix.length = matrix[i].length = n.
  • -10^9 <= matrix[i][j] <= 10^9.
  • 1 <= turns <= 4.

More Hudson River Trading Online Assessment questions

  • Count Palindrome Addition ChoicesOA · Seen Nov 2026
  • Count Multiples of Three with Two SevensOA · Seen Oct 2026
  • Recursively Expanded Shell Command CountsOA · Seen Oct 2026
  • Maximum Diamond SumOA · Seen Oct 2026
  • Smallest Most-Lit Street PositionOA · Seen Oct 2026
  • Rearrange String by Alternating EndsOA · Seen Sep 2026
  • Most Items Within Budget from a Start IndexOA · Seen Sep 2026
  • Count Sawtooth SubarraysOA · Seen Aug 2026
  • Backtick Identifier ConverterOA · Seen Jun 2026
  • Max Minus Min Weight in Every SubtreeOA · Seen Sep 2025

Similar questions at other companies

  • Rotate Matrix Regions Around the DiagonalsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Robot Navigation Around LasersRoblox · OARoblox interview questions
  • Leaves Remaining After Wind GustsOpenAI · OAOpenAI interview questions
  • Apply a Reversi MoveAmazon · OA
  • Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
  • Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Sort Every Matrix Border LayerCapital One · OACapital One interview questions
  • Rotate a Square Matrix ClockwiseVisa · OAVisa interview questions
  • Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions

Hudson River Trading interview experiences

  • Hudson River Trading Quant Video Interview: 1 Experience
  • HRT SWE Intern and Onsites: 34 Experiences (Part 2 of 2)
  • HRT Python Track Interviews: 64 Experiences (Part 1 of 2)
  • HRT New Grad Python Track Interviews: 9 Experiences
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public int[][] rotateMatrixOverDiagonals(int[][] matrix, int turns) {
        // Write your code here.
    }
}
Checking account…