Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

Stretch Problem: Rotate an Image (medium)

This problem is optional. It is here for readers who want a harder grid question, and nothing later in the course depends on it.

Problem Statement

You are given an n x n matrix representing an image. Rotate the image by 90 degrees clockwise and return it.

Do the rotation in place, without allocating a second matrix.

Examples

Example 1

  • Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  • Expected Output: [[7, 4, 1], [8, 5, 2], [9, 6, 3]]
  • Justification: The first column read from the bottom up becomes the first row, and so on for the other columns.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content