Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Spiral matrix

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 [].

Requirements

  • Every cell appears exactly once.

Constraints

  • Up to 100 x 100.
  • Rows have equal length.

Examples

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

intermediate

Spiral matrix

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 `[]`.