Question bankPricingSign in

Rotate Image 90 Degrees

Math & GeometryMedium1:30

Given an n x n 2D matrix representing an image, rotate it 90 degrees clockwise in place (without using another matrix).

For example:

Input:         Output:
1  2  3        7  4  1
4  5  6   ->   8  5  2
7  8  9        9  6  3

Explain your approach for rotating in place, describe the pattern of how elements move, and analyze the time and space complexity.

How to approach it

  • Hint 1

    A 90-degree clockwise rotation can be decomposed into two simpler operations on the matrix. What are they?

  • Hint 2

    Try transposing the matrix (swap rows and columns) and then reversing each row.

  • Hint 3

    Alternatively, think about rotating in layers -- the outermost ring first, then the next ring inward.

Ready to answer it out loud?

Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.