Rotate Image

interview_workbook/leetcode/math_geometry /app/src/interview_workbook/leetcode/math_geometry/rotate_image.py
View Source

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():
    """TODO: Implement demo function."""
    pass


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="",
)