Question
Return all values of an `m × n` matrix in clockwise spiral order, beginning at the top-left corner. ```python def spiral_order(matrix: list[list[int]]) -> list[int]: ... ``` Use `O(1)` auxiliary space excluding the returned list, and do not mutate the matrix. Handle empty, single-row, single-column, square, and rectangular matrices. ## Staged follow-ups 1. Generate an `n × n` matrix filled from `1` through `n²` in spiral order. 2. Expose a lazy iterator rather than building the result. 3. Traverse counterclockwise or from an arbitrary corner without duplicating the entire algorithm.