1. Four Shrinking Boundaries Optimal
Intuition
Hold four edges — top, bottom, left, right — and consume one at a time, pulling the boundary in behind you. The two guards before the bottom and left passes are what stop a single remaining row or column being read twice: after the top row is consumed, top may have passed bottom, and the bottom pass would replay it. [[1],[2],[3]] is in the tests for exactly that.
Algorithm
1. Walk the top row left to right; drop the top boundary.
2. Walk the right column downward; drop the right boundary.
3. If rows remain, walk the bottom row right to left; raise the bottom.
4. If columns remain, walk the left column upward; raise the left.
5. Repeat while the boundaries have not crossed.
Time & Space
Time O(m x n). Space O(1) beyond the output.