Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 08 · DSA · Worked problems, in English · about 19 min to read

Play it as a journeyTutor comes with a plan

Clinic #30: Rotate Image

Pattern: Matrix / math · LC 48

Arrays and Strings
Arrays and Strings · Open board

Shows one row of same-size boxes, and two fingers walking that row from both ends toward the middle. This clinic stacks those rows into a square, and the two fingers turn out to be half of the answer.

Before you start. Arrays & Strings gave you a row of numbered boxes, where you can reach any box by its number without walking past the others, and a trick for reversing the row: one finger at each end, swap, step both inward, stop when they meet. The only other thing you need is that the counting starts at 0, so the first box in a row of three is box 0 and the last is box 2.

Lesson 69 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • A mosaic laid on its side, and a wall you cannot take down
  • The grid is a matrix: a row number and a column number for every tile
  • The wrong first idea: move each tile straight to its new home
  • Four tiles that chase each other round a layer
  • The second way: a transpose, then flip each row
  • The tell: a square, a quarter-turn, and “in place”
  • Solution ladder
  • The two methods, walked on 3 by 3
  • Memory and timings (measured, 2026-09-27)
  • The other direction
  • First time in an interview: the path
  • The matrix ladder: easy, medium, hard

Terms it explains: LC 48, matrix, index, in place, layer, transpose, "n x n", "rotate by 90 degrees", "in-place", transpose, then reverse rows, O(n²), O(1), BEST: two simple loops, Test, array, capacity vs length, dynamic array, fixed vs variable window, Floyd's cycle detection, immutable, in-place, KMP, prefix sum, sliding window, string, StringBuilder / join, two-pointer.

Review DSA