Python data engineering interview problem. Difficulty: intermediate. Pattern: Matrix. About 14 minutes. Part of the Pro drill bank.
Read a rectangular matrix in clockwise spiral order. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement spiral_order(matrix: list[list[int]]) -> list[int]. Return all elements in clockwise spiral order, starting at the top-left corner: across the top row, down the right column, back along the bottom row, up the left column, then inward. The matrix can be any rectangle. An empty matrix, or one whose rows are empty, gives [].
Input: spiral_order([[1, 2, 3]]) Output: [1, 2, 3] A single row is read once, left to right.
Topics: lakebench, python, matrix, traversal.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Read a rectangular matrix in clockwise spiral order.
Implement `spiral_order(matrix: list[list[int]]) -> list[int]`. Return all elements in clockwise spiral order, starting at the top-left corner: across the top row, down the right column, back along the bottom row, up the left column, then inward. The matrix can be any rectangle. An empty matrix, or one whose rows are empty, gives `[]`.