← Back to challenges

Rotate-Transform the Two-Dimensional Matrix

JavaScriptHardalgorithmsarraysinterviewloops

Instructions

Create a function to rotate a two-dimensional matrix of N * N integer elements num times, where if num is positive, the rotation is clockwise, and if not, counterclockwise.

Examples

rotateTransform([
  [2, 4],
  [0, 0]
], 1) ➞ [
  [0, 2],
  [0, 4]
]
rotateTransform([
  [2, 4],
  [0, 0]
], -1) ➞ [
  [4, 0],
  [2, 0]
]

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.