Matrix Problems for Coding Interviews
209 Matrix problems from real coding interviews, each with test cases you can run online. By difficulty they split into 53 basic, 105 intermediate and 51 advanced. The companies that ask them most often are Google, Amazon, 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
- Pascal Triangle Value (Intermediate)
- Unique Grid Paths (Intermediate)
- Matrix Spiral Order (Intermediate)
- Maximum Submatrix Sum (Basic)
- Largest All-Ones Rectangle (Intermediate)
- Largest Island After One Flip (Intermediate)
- Minimum Falling Path Without Repeated Columns (Intermediate)
- Matrix Row and Column Zeroing (Intermediate)
- Count Islands With Diagonal Adjacency (Advanced)
- Minimum Cost to Make a Valid Grid Path (Advanced)
- Shortest Bridge Between Two Islands (Intermediate)
- Minimum Path Sum (Intermediate)
- Unique Paths With Obstacles (Intermediate)
- Shortest Path In Binary Grid (Intermediate)
- Flood Fill Region Size (Basic)
- Tree Vertical Traversal (Intermediate)
- Count Ways to Tile Board (Intermediate)
- Dynamic Island Additions (Advanced)
- Minimum Cost Path With Portals (Intermediate)
- Minimum Number of Reflections (Advanced)
- Count Distinct Islands Shapes (Basic)
- Maximum Number of Points With Cost (Advanced)
- Minimum Cost to Cut a Board (Intermediate)
- Shortest Path Through Maze Keys and Doors (Advanced)
- Minimum Cost to Collect All Keys (Intermediate)
- Minimum Number of Buses (Intermediate)
- Walls and Gates Distance (Advanced)
- Minimum Cost to Type a String (Intermediate)
- Minimum Moves to Spread Stones (Advanced)
- Find Peak in 2D Grid (Intermediate)
- Median of Row-Wise Sorted Matrix (Intermediate)
- Count Negative Values in Sorted Matrix (Advanced)
- Cherry Pickup With Two Agents (Basic)
- Optimal Matrix Chain Multiplication (Intermediate)
- Traveling Salesperson With Time Windows (Advanced)
- Vehicle Routing With Capacity (Intermediate)
- A-Star Pathfinding (Intermediate)
- Sliding Puzzle Solver (Basic)
- Nonogram Solver (Intermediate)
- Gaussian Elimination Solver (Intermediate)
- Spiral Matrix From Linked List (Intermediate)
- Number of Islands (Basic)
- Rotting Oranges (Intermediate)
- Surrounded Regions (Intermediate)
- Pacific Atlantic Water Flow (Intermediate)
- Path With Minimum Effort (Intermediate)
- Swim in Rising Water (Advanced)
- Snakes and Ladders (Intermediate)
- Distance to Nearest Zero (Intermediate)
- As Far From Land as Possible (Intermediate)
- Number of Enclaves (Intermediate)
- Most Stones Removed (Intermediate)
- Regions Cut by Slashes (Intermediate)
- Minimum Obstacle Removal (Advanced)
- Grid Path With Obstacle Eliminations (Advanced)
- Island Perimeter (Basic)
- Number of Closed Islands (Intermediate)
- Shortest Distance From All Buildings (Advanced)
- Maximal Square (Intermediate)
- Out of Boundary Paths (Intermediate)
- Minimum Falling Path Sum (Intermediate)
- Count Square Submatrices (Intermediate)
- Paint N x 3 Grid (Intermediate)
- Grid Paths Divisible by K (Advanced)
- Longest Increasing Path in a Matrix (Advanced)
- Number of Increasing Paths in a Grid (Advanced)
- Word Search (Intermediate)
- Word Search II Count (Advanced)
- Car Pooling (Intermediate)
- Valid Sudoku (Intermediate)
- Rotate Image (Intermediate)
- Range Sum Query 2D (Intermediate)
- Diagonal Traverse (Intermediate)
- Game of Life Step (Intermediate)
- Toeplitz Matrix (Basic)
- Search a 2D Matrix (Intermediate)
- Search a 2D Matrix II (Intermediate)
- Kth Smallest in a Sorted Matrix (Intermediate)
- Kth Smallest Number in Multiplication Table (Advanced)
- N-Queens Count (Advanced)
Related
- Basic Matrix problems
- Intermediate Matrix problems
- Advanced Matrix problems
- Practice coding problems online
- All interview guides
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.