Algorithm · Atlassian · Medium
For an $$m \times n$$ matrix, list its entries by walking around the outside clockwise, then continuing inward in the same spiral pattern. Input: Output: [2, 4, 6, 12, 18, 16, 14, 8, 10] The result follows the outer boundary first and finishes with the center value. Example Input: 3 3 Output: [5, 1, 7, 2, 6, 4, 8, 3, 9] The traversal circles the perimeter clockwise before visiting 9 in the middle.