Talentd
FleetCode
Make and follow sheets.Sign in

Matrix Problems (279)

Problems tagged with Matrix. Start with the easy ones, then move to medium and hard.

41 Easy163 Medium75 Hard

Learn these first

1
Array

Matrices are typically implemented as 2D arrays. Understanding indexing, traversal, and memory layout in arrays is essential before solving matrix problems.

2
Prefix Sum

Prefix sums allow efficient calculation of submatrix sums and range queries, reducing repeated computation in matrix problems.

3
Depth-First Search

DFS is widely used for exploring grids, such as counting islands or exploring connected components in a matrix.

4
Dynamic Programming

Many advanced matrix problems require DP to track optimal paths, minimum costs, or cumulative states across rows and columns.

5
Breadth-First Search

BFS helps solve shortest-path and level-based traversal problems in grids, especially when each cell represents a node in a graph.

TitleSolutionAcceptDifficultyTopics
Solution73.9%Medium
Array, Breadth-First Search +3· 20 companies
723. Candy CrushVideoPremium
Solution77.6%Medium
Array, Matrix +2· 11 companies
733. Flood FillVideo
Solution68.6%Easy
Array, Breadth-First Search +2· 12 companies
741. Cherry PickupVideo
Solution40.4%Hard
Array, Dynamic Programming +1· 10 companies
749. Contain VirusVideo
Solution56.5%Hard
Array, Breadth-First Search +3· 3 companies
Solution67.8%Medium
Array, Dynamic Programming +2· 1 company
766. Toeplitz MatrixVideo
Solution69.8%Easy
Array, Matrix· 4 companies
773. Sliding PuzzleVideo
Solution74.3%Hard
Array, Backtracking +4· 7 companies
Solution68.3%Hard
Array, Binary Search +5· 8 companies
Solution51.9%Hard
Array, Bit Manipulation +2· 2 companies
Solution34.7%Medium
Array, Matrix· 3 companies
Solution37.7%Hard
Array, Matrix +1· 3 companies
Solution86.2%Medium
Array, Greedy +1· 3 companies
Solution57.0%Hard
Array, Breadth-First Search +3· 16 companies
Solution83.6%Easy
Array, Bit Manipulation +3· 6 companies
835. Image OverlapVideo
Solution70.6%Medium
Array, Matrix· 1 company
Solution55.1%Medium
Array, Hash Table +2· 5 companies
Solution80.3%Medium
Array, Bit Manipulation +2· 3 companies
Solution77.4%Easy
Array, Matrix +1· 7 companies
Solution76.9%Easy
Array, Geometry +2· 1 company
Solution84.6%Medium
Array, Matrix +1· 8 companies
Solution71.2%Easy
Array, Geometry +2· 1 company
Solution48.0%Medium
Array, Breadth-First Search +1· 12 companies
Solution60.8%Medium
Array, Dynamic Programming +1· 8 companies
934. Shortest BridgeVideo
Solution59.9%Medium
Array, Breadth-First Search +2· 16 companies
Solution77.8%Medium
Array, Breadth-First Search +4· 6 companies
Solution82.8%Hard
Array, Backtracking +2· 7 companies
994. Rotting OrangesVideo
Solution59.5%Medium
Array, Breadth-First Search +1· 52 companies
Solution72.2%Easy
Array, Matrix +1· 2 companies
Solution72.2%Medium
Array, Breadth-First Search +3· 5 companies
Solution74.6%Easy
Array, Geometry +3· 1 company
Solution51.8%Medium
Array, Breadth-First Search +2· 3 companies
Solution51.8%Medium
Array, Breadth-First Search +1· 15 companies
Solution54.6%Medium
Array, Binary Search +5· 3 companies
Solution52.7%Medium
Array, Dynamic Programming +1· 4 companies
Solution52.2%Medium
Array, Breadth-First Search +2· 7 companies
Solution76.5%Medium
Array, Binary Search +3· 2 companies
Solution68.6%Medium
Array, Backtracking +1· 5 companies
Solution72.6%Medium
Array, Matrix +1· 2 companies
Solution49.4%Medium
Array, Greedy +1· 1 company
Solution70.4%Medium
Array, Breadth-First Search +3· 5 companies
1260. Shift 2D GridVideo
Solution74.3%Easy
Array, Matrix +1· 1 company
Solution54.6%Easy
Array, Hash Table +2· 7 companies
Showing 51–100 of 278

More about Matrix

A matrix is a two-dimensional data structure arranged in rows and columns, commonly represented as a grid. In data structures and algorithms (DSA), matrices are typically implemented using a 2D Array. Many real-world problems—such as image processing, game boards, maps, and spreadsheets—naturally map to matrix representations. Because of this, matrix problems frequently appear in coding interviews and competitive programming.

Matrix questions test a developer’s ability to think in multiple dimensions, manage indices carefully, and apply algorithmic patterns efficiently. Interviewers often use matrix-based problems to evaluate how well you handle traversal strategies, boundary conditions, and space optimization. These problems are common in interviews at top tech companies because they combine multiple DSA concepts in a single challenge.

Most matrix problems rely on a handful of recurring patterns. These include row-wise and column-wise traversal, spiral traversal, matrix rotation, and searching within sorted grids. Graph-style exploration is also common, where each cell acts like a node connected to neighbors. In these cases, algorithms such as Depth-First Search and Breadth-First Search are frequently used to explore connected components, islands, or shortest paths.

More advanced matrix problems combine grid traversal with optimization techniques. For example, dynamic state transitions often require Dynamic Programming, while fast region calculations rely on Prefix Sum preprocessing. Recognizing which technique applies to a given grid problem is a key skill for solving interview questions efficiently.

On FleetCode, you can practice ranging from beginner-friendly grid traversals to advanced dynamic programming and graph-based challenges. By mastering these patterns, you’ll build strong problem-solving intuition and significantly improve your performance in technical coding interviews.

Matrix: common questions

Is Matrix an important topic for FAANG interviews?

Yes. Matrix problems are frequently asked in FAANG and other top tech company interviews because they combine multiple concepts like arrays, graph traversal, and dynamic programming. They are commonly used to evaluate problem-solving and edge-case handling.

What are common patterns used in Matrix DSA problems?

Typical matrix patterns include directional traversal (up, down, left, right), spiral traversal, multi-source BFS, connected component discovery, in-place matrix transformation, and prefix sum preprocessing for submatrix queries.

What is the best way to learn Matrix problems in DSA?

Start with simple row and column traversals, then practice common patterns like spiral traversal, matrix rotation, and grid searches. After that, move to BFS/DFS island problems and dynamic programming on grids to build deeper problem-solving skills.

Why are matrix problems sometimes treated like graph problems?

In many matrix problems, each cell can be considered a node connected to its neighbors. This allows algorithms like BFS and DFS to be applied for exploring regions, finding shortest paths, or identifying connected components within the grid.

What are the most common Matrix problems asked in coding interviews?

Common matrix interview problems include Number of Islands, Spiral Matrix traversal, Rotate Image, Search in a 2D Matrix, and Set Matrix Zeroes. These questions test traversal, boundary handling, and algorithmic patterns such as BFS, DFS, and in-place transformations.