Approach hintTry it first, then revealHide
Maintain four boundaries, walk one side at a time, and shrink the matching boundary after each side. Check that the boundaries have not crossed before walking the last two sides of a ring.
More in Matrix (2-D Arrays)
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Matrix Diagonal Sum | LeetCode | Easy | Solve Matrix Diagonal Sum on LeetCode (opens in a new tab) | |||
| 2 | Beautiful Matrix | Codeforces | Easy 800 | Solve Beautiful Matrix on Codeforces (opens in a new tab) | |||
| 3 | Transpose Matrix | LeetCode | Easy | Solve Transpose Matrix on LeetCode (opens in a new tab) | |||
| 4 | Target Practice | Codeforces | Easy 800 | Solve Target Practice on Codeforces (opens in a new tab) | |||
| 5 | Pascal's Triangle | LeetCode | Easy | Solve Pascal's Triangle on LeetCode (opens in a new tab) | |||
| 6 | Lights Out | Codeforces | Easy 900 | Solve Lights Out on Codeforces (opens in a new tab) | |||
| 7 | Set Matrix Zeroes | LeetCode | Medium | Solve Set Matrix Zeroes on LeetCode (opens in a new tab) | |||
| 8 | Valid Sudoku | LeetCode | Medium | Solve Valid Sudoku on LeetCode (opens in a new tab) | |||
| 9 | Rotate Image | LeetCode | Medium | Solve Rotate Image on LeetCode (opens in a new tab) | |||
| 10 | Spiral Matrix | LeetCode | Medium | Solve Spiral Matrix on LeetCode (opens in a new tab) |