10. 2D Arrays & Matrix
Rotate, spiral, search and in-place tricks on grids.
π¬ Episode 14: video coming soon
Your progress0 of 10
2easy
8medium
0hard
Understand the topic
A matrix is an array of rows. Cell (r, c) is row r, column c. Most matrix tricks are index tricks: the main diagonal is (i, i), the other diagonal is (i, n-1-i), and transposing swaps (r, c) with (c, r).
For in-place problems, look for a spare place to store information: the first row and column as markers, or a second bit in each cell.
| # | Problem | Pattern | Level | ||
|---|---|---|---|---|---|
| 1 | Matrix Diagonal Sum #1572 | Index patterns | Easy | LeetCode β | |
| 2 | Transpose Matrix #867 | Index swap | Easy | LeetCode β | |
| 3 | Rotate Image #48 | Transpose + reverse rows | Medium | LeetCode β | |
| 4 | Spiral Matrix #54 | Shrinking boundaries | Medium | LeetCode β | |
| 5 | Spiral Matrix II #59 | Shrinking boundaries | Medium | LeetCode β | |
| 6 | Set Matrix Zeroes #73 | First row/column as markers | Medium | LeetCode β | |
| 7 | Search a 2D Matrix #74 | Binary search on flattened index | Medium | LeetCode β | |
| 8 | Search a 2D Matrix II #240 | Staircase search | Medium | LeetCode β | |
| 9 | Valid Sudoku #36 | Row/column/box sets | Medium | LeetCode β | |
| 10 | Game of Life #289 | In-place state encoding | Medium | LeetCode β |
Nothing matches that filter.
Work top to bottom β each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.