Rotate Matrix

ARRAY
MATRIX

Problem

Given a matrix representing a N x N 2D grid, rotate the matrix by 90 degrees in the clockwise direction. The rotation should be done in-place, which means modifying the input matrix directly without using an additional matrix for the rotation.

Examples

rotateMatrix([ [1,2,3], [4,5,6], [7,8,9] ]); /* returns [ [7,4,1], [8,5,2], [9,6,3] ] Each value is rotated by 90 degrees clockwise */
Loading...
1
2
3
4
5
6
7
8
9