Algorithm Notes
Summary: Rotate Image — notes not yet curated.
Time: Estimate via loops/recurrences; common classes: O(1), O(log n), O(n), O(n log n), O(n^2)
Space: Count auxiliary structures and recursion depth.
Tip: See the Big-O Guide for how to derive bounds and compare trade-offs.
Big-O Guide
Source
"""
Rotate Image
TODO: Add problem description
"""
from src.interview_workbook.leetcode._registry import register_problem
from src.interview_workbook.leetcode._types import Category, Difficulty
class Solution:
def solve(self, *args) -> None:
"""Rotate the matrix 90 degrees clockwise in-place."""
matrix = args[0]
n = len(matrix)
# transpose
for i in range(n):
for j in range(i + 1, n):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
# reverse rows
for row in matrix:
row.reverse()
return matrix
def demo():
"""Run a simple demonstration for Rotate Image problem."""
s = Solution()
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(f"Initial matrix: {matrix}")
result = s.solve(matrix)
print(f"Rotated matrix: {matrix}")
return f"Rotated: {result}"
register_problem(
id=48,
slug="rotate_image",
title="Rotate Image",
category=Category.MATH_GEOMETRY,
difficulty=Difficulty.MEDIUM,
tags=["array", "math"],
url="https://leetcode.com/problems/rotate-image/",
notes="",
)