Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Rotating Observatory

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Transpose, then reverse every row: The Rotating Observatory.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Rotate matrix 90 degrees matches the clues
  2. 2Keep this true after every move: after transpose and row reversal, old cell [r,c] occupies [c,n-1-r]
  3. 3Reach the result within O(n squared) time and O(1) extra space

Rules and pressure

  • Target cost: O(n squared) time and O(1) extra space
  • State rule: after transpose and row reversal, old cell [r,c] occupies [c,n-1-r]
Lesson 1 of 3

Live algorithm trace

Rotate matrix 90 degrees

Complete execution
1 of 5

Begin swaps strictly above the main diagonal.

1for row
2for col after diagonal
3swap matrix[row][col] with matrix[col][row]
4for each row
5reverse the row
6return matrix
phase = transpose
Truth to preserve / Cost target
Truth to preserve

after transpose and row reversal, old cell [r,c] occupies [c,n-1-r]

Cost target

O(n squared) time and O(1) extra space

A clockwise quarter-turn maps row and column positions. Transposing across the main diagonal and reversing each row performs that mapping in place.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead