Grokking Data Structures & Algorithms for Coding Interviews
0% completed
Stretch Problem: Spiral Matrix (medium)
This problem is optional. The three problems above cover what the chapter teaches. This one is here for readers who want a harder grid question, and nothing later in the course depends on it.
Problem Statement
Given an m x n matrix, return all of its values in spiral order: left to right along the top row, down the right column, right to left along the bottom row, up the left column, then inward and around again.
Examples
Example 1
- Input: matrix =
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] - Expected Output:
[1, 2, 3, 6, 9, 8, 7, 4, 5]
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%