Browse Curriculum

The Matrices Pattern

A 2D grid is a graph whose neighbours are implicit: each cell connects to the cells beside it. Most matrix problems are BFS, DFS or DP with row and column bookkeeping, plus in-place tricks for rotation and traversal.

3
Interactive problems
1
Free to open

How to recognise a matrices problem

The input is a 2D grid and the question involves islands, regions, flood fill, spiral or diagonal traversal, path counting, or rotating and transposing in place.

Time and space complexity

O(rows × cols) for a full traversal. In-place transformations keep space at O(1) beyond the input.

Matrices practice problems

Each problem pairs a worked explanation with an interactive visualizer you step through yourself, plus the implementation in JavaScript, Python, Java and C++.


Related patterns and concepts

Matrices is one of the 16 coding interview patterns, and its problems also appear in the DSA 75 interview sprint.