Problem link: https://leetcode.com/problems/rotate-image/

Image for post
Image for post
Photo by Kelly Sikkema on Unsplash

The purpose of this problem is to rotate a matrix 90 degrees to the right.

Here are a couple example inputs and outputs:

Image for post
Image for post

Note that the matrix must have the same number of rows and columns. Above there are examples of 4x4, 3x3, and 2x2 inputs.

Step 1 — Transpose:

The definition of transpose from lexico.com is the following:

“Cause (two or more things) to change places with each other”

Imagine that the matix is a sqaure piece of paper. We fold the square diagonally so that the crease line will go from the top left corner to the bottom right corner. Then we flip the paper on the axis of our crease. Even though we flipped the paper over, the numbers on the other side of the paper show through. …

About

Silas Burger

I’m a software engineer who is always learning. I’m currently learning backend development in Go.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store