Member-only story

Rotate a Matrix by 90 degrees | Coding Interview | Matrix

Ganesh Prasad
5 min readJan 18, 2022

--

Rotating a matrix/image by 90 degrees.

I will simplify the solution using some animations. You might encounter this problem during interviews as “Rotate an image,” it has been asked by companies like Bloomberg, Uber, Google, Apple, Microsoft, Facebook, and Amazon.

If you are preparing for an upcoming interview, you may find these system design interview notes helpful.

This article is part of the 30 days preparation plan 🤯. And this is the last matrix-based problem we are going to cover🤩.

Table of Contents

  1. Description
  2. Approach 1 (placing the values in their correct positions)
  3. Code
  4. Time & Space Complexity
  5. Approach 2 (Transpose and Reflect)
  6. Code
  7. Time & Space Complexity

Description

We are given a square matrix of size n and we want to rotate it by 90 degrees. Since images are matrices where each pixel is an intensity level of…

--

--

Ganesh Prasad
Ganesh Prasad

Written by Ganesh Prasad

Backend Developer at Appscrip | C++ veteran, 💜 Dart

No responses yet