Rotate a Square Map Tile Clockwise In Place

Last updated: November 29, 2026

Quick Overview

A map renderer stores an N x N tile of pixel values as a list of lists. Rotate the tile 90 degrees clockwise in place, without allocating a second matrix, so the driver app can display it in landscape mode.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


A map renderer stores an N x N tile of pixel values as a list of lists. Rotate the tile 90 degrees clockwise in place, without allocating a second matrix, so the driver app can display it in landscape mode.

An Online Assessment style matrix problem tied to the map tiles the Uber driver app renders. The grader checks the transpose-then-reverse trick or a layer-by-layer four-way swap, and correct index math.

What the Interviewer Expects
  • States the index mapping (r, c) to (c, N-1-r)
  • Transposes across the main diagonal
  • Reverses each row
  • Uses O(1) extra space
  • Tests 1x1, 2x2 and odd sizes
Key Topics to Cover
Matrix
In-place transformation
Index math
Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you rotate counterclockwise?
  • How would you rotate a non-square M x N tile?
  • How would you rotate by 180 degrees in one pass?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: a square list of lists, N from 0 to about 1000. Output: none; the matrix is modified in place. Clockwise rotation sends the element at (r, c) to (c, N - 1 - r)....

High-Level Design

Clockwise rotation equals a transpose (swap (r, c) with (c, r)) followed by reversing every row. The transpose maps (r, c) to (c, r), and the row reversal maps (c, r) to (c, N - 1 - r), wh...


Submit Your Answer
Markdown supported