less than 1 minute read

Given a two-dimensional square matrix, rotate in-place it 90 degrees counter-clockwise.

Constraints

  • n = m ≤ 250 where n and m are the number of rows and columns in matrix

https://binarysearch.com/problems/Rotate-by-90-Degrees-Counter-Clockwise

Examples

Example 1

Input

  • matrix =
[[1,2,3],
 [4,5,6],
 [7,8,9]]

Output

  • answer = [[3, 6, 9], [2, 5, 8], [1, 4, 7]]

Solution

Leave a comment