← 返回 uber 的题目列表Rotate Image In Place
类型:qbank
Phone-screen prompt equivalent to Rotate Image. Given an `n x n` matrix representing an image, rotate it 90 degrees clockwise in place without allocating another matrix.
Requirements
Input: an n x n 2-D matrix representing an image.
Rotate the matrix 90 degrees clockwise.
Modify the input matrix in place; do not return a newly allocated matrix.
Preserve every element exactly once after rotation.
Notes
Clarify in-place expectations before coding: a temporary scalar is fine, but a second n x n matrix defeats the prompt.
Walk through one odd-size matrix and one even-size matrix; off-by-one layer boundaries are the usual bug.
Preparation
Practice both common formulations: transpose + reverse each row, and four-way layer swaps.
Write tests for 1x1, 2x2, and 3x3 matrices before the interview so you can trace quickly.