Rotate Image

Medium · Matrix · Array · Matrix · Math

Problem

Rotate an n x n matrix by 90 degrees clockwise, in place. Do not allocate a second matrix.

Examples

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]

The first column becomes the first row, reversed.

Input: matrix = [[1,2],[3,4]]
Output: [[3,1],[4,2]]

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…