Topic
Matrix interview questions
All 6 Matrix problems from the curated set, easiest first — a core topic for 10 of the 29 engineering roles.
- Easy
- 1
- Medium
- 5
- Hard
- 0
- Sheets
- 2
What Matrix is
Updated 2026-09-09A matrix is a flat grid of cells laid out in rows and columns, like a checkerboard or a spreadsheet. Each cell has an address made of two numbers: its row index going down and its column index going across. Because computer memory stores these rows one after another or as arrays of arrays, jumping straight to any individual cell takes the same tiny fraction of time no matter where it sits on the board.
When to reach for it
Reach for matrix techniques when the input is a two-dimensional grid, board, or map. Common prompts include walking through a maze, finding connected islands of land in water, rotating an image ninety degrees in place, or reading numbers in a spiral. Words like rows, columns, neighbors, adjacent squares, or diagonal lines are clear signs. It also appears in grid planning where each cell depends on the values above and to the left.
How to think about it
Think of navigating the grid using directional coordinate offsets. Define row and column step arrays for moving up, down, left, and right. Always check that new row and column indices stay strictly between zero and the board boundaries before reading cell values. For spiral scans, track four boundary lines for top, bottom, left, and right, shrinking them inward after reading each side. When searching connected regions, mark visited cells directly or write a marker value into the cell to avoid looping.
What each operation costs
| Operation | Time |
|---|---|
| read or write cell by row and column | O(1) |
| visit every cell across m rows and n columns | O(m * n) |
| rotate square matrix in place | O(n^2) |
What usually goes wrong
- Flipping row and column dimensions by mixing up grid height with grid width, causing index out of bounds crashes on rectangular grids where row and column counts differ.
- Reading neighbor cells without first confirming that the row and column coordinates are within valid bounds between zero and the board edges.
- Forgetting to update inner boundary limits during spiral traversal, which causes single-row or single-column matrices to print duplicate entries.
Every Matrix problem, easiest first
Roles that need Matrix
If you are targeting one of these, Matrix sits early in your path rather than being optional.
Track Matrix in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks. Free.
Start freeMatrix interview questions, answered
How many Matrix problems should I solve for interviews?
6 curated Matrix problems cover the patterns interviews repeat: 1 easy, 5 medium and 0 hard. They are drawn from 2 widely used sheets, deduplicated, and ordered easiest first.
Is Matrix actually asked in coding interviews?
Yes, though how much depends on the role. Matrix is a core topic for 10 of the 29 engineering roles tracked here, including Data Engineer, ML Engineer, Data Analyst. For other roles it is lower frequency and belongs later in a study plan.
Which Matrix problem should I start with?
Start with Count Negative Numbers in Sorted Matrix (Easy). The list on this page is ordered easiest first for that reason, so working top to bottom builds the pattern before the harder variations arrive.
Other topics
Problem set and role mapping as of .