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
- 1Recognize when Rotate matrix 90 degrees matches the clues
- 2Keep this true after every move: after transpose and row reversal, old cell [r,c] occupies [c,n-1-r]
- 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 execution1 of 5
Begin swaps strictly above the main diagonal.
1
for row2
for col after diagonal3
swap matrix[row][col] with matrix[col][row]4
for each row5
reverse the row6
return matrixphase = 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?