Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

matrix =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Peel the matrix layer by layer using four boundaries.

Approach

Maintain top, bottom, left, right. Traverse:

  1. top row left->right
  2. right col top->bottom
  3. bottom row right->left
  4. left col bottom->top Then shrink bounds.
Code
Loading...
Complexity
Time: O(mn)
Space: O(1) extra
Solution
Updated: 2026-02-23

Idea

Peel the matrix layer by layer using four boundaries.

Approach

Maintain top, bottom, left, right. Traverse:

  1. top row left->right
  2. right col top->bottom
  3. bottom row right->left
  4. left col bottom->top Then shrink bounds.
Code
Loading...
Complexity
Time: O(mn)
Space: O(1) extra