Lesson overview · Free interview practice

Matrix Traversal

Navigate through matrices efficiently.

Topics in the full lesson
  • Concept and Use Cases
  • When to Use
  • Time and Space Complexity
  • Common Problems
  • Counting Islands using DFS
  • Counting Islands using BFS
  • Max Area of Island

Practice Problems

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

Completion marks record your own progress, not an automatically checked result. The task type does not determine whether it is optional.

CodingMedium

Diagonal Traverse

Question

Given an m × n integer matrix, return an array of all the elements of the matrix in diagonal order — traversing each anti-diagonal alternately upward and downward.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

CodingMedium

Spiral Matrix

Question

Given an m × n matrix, return all elements of the matrix in spiral order: start at the top-left and traverse right, then down, then left, then up, repeating inward until every element is visited.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

CodingMedium

Set Matrix Zeroes

Question

Given an m × n integer matrix, if an element is 0, set its entire row and column to 0. Do it in-place, and aim for O(1) extra space (use the first row/column as marker storage).

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Matrix Traversal material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium