Basic Matrix Problems for Coding Interviews
53 basic Matrix problems from real coding interviews, each with test cases you can run online. By difficulty they split into 53 basic, 0 intermediate and 0 advanced. The companies that ask them most often are Amazon, Google, Microsoft, Meta.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Maximum Submatrix Sum (Basic)
- Flood Fill Region Size (Basic)
- Count Distinct Islands Shapes (Basic)
- Cherry Pickup With Two Agents (Basic)
- Sliding Puzzle Solver (Basic)
- Number of Islands (Basic)
- Island Perimeter (Basic)
- Toeplitz Matrix (Basic)
- Battleships in a Board (Basic)
- Lonely Pixel Count (Basic)
- Divisor Game (Basic)
- Excel Sheet Cells in Range (Basic)
- Cells With Odd Values in a Matrix (Basic)
- Lucky Numbers in a Matrix (Basic)
- Matrix Diagonal Sum (Basic)
- Transpose Matrix (Basic)
- Flipping an Image (Basic)
- Reshape the Matrix (Basic)
- Range Addition II (Basic)
- Count Total Colored Cells (Basic)
- Largest Square of Ones in Grid (Basic)
- Maximum Gold Collected Moving Right or Down (Basic)
- Maximum Sum Submatrix of Fixed Size (Basic)
- Chocolate Break Game Winner (Basic)
- Magic Square Check (Basic)
- Latin Square Check (Basic)
- Anti-Diagonal Sums of Matrix (Basic)
- Saddle Points Count (Basic)
- Value at Position in Snake Fill (Basic)
- Count Distinct Rows in Matrix (Basic)
- Diagonal Difference of Matrix (Basic)
- Robot Path Distinct Cells Visited (Basic)
- Determinant of 3x3 Matrix (Basic)
- Symmetric Matrix Check (Basic)
- Upper Triangular Matrix Check (Basic)
- Minesweeper Neighbor Counts (Basic)
- Bus Peak Passenger Load (Basic)
- Border Cells Sum (Basic)
- Anti-Diagonal Sum (Basic)
- Non-Decreasing Rows Count (Basic)
- Column With Largest Sum (Basic)
- Checkerboard Pattern Check (Basic)
- All Zero Rows Count (Basic)
- Palindromic Rows Count (Basic)
- Largest Side Neighbour Sum (Basic)
- Most Distinct Values in a Row (Basic)
- Snake Order Even Position Sum (Basic)
- Strictly Increasing Rows Count (Basic)
- Row Sum Spread (Basic)
- Cells Equal to Index Sum (Basic)
- Row Flips for Most Ones (Basic)
- Squares in a Rectangular Grid (Basic)
- Rectangles in a Grid Count (Basic)
Related
Frequently asked questions
How do I get good at matrix problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run matrix problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.