FastPrepSpiral Matrix
Problems/Spiral Matrix

Spiral Matrix

Athenahealth logoAthenahealth● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from an Athenahealth interview for a Member of Technical Staff role that asked for about two years of experience. In the second live round, after an online coding test and a first coding round, the candidate was asked to solve Spiral Matrix, and the round also covered backend topics.

The report names the problem and gives no rules, examples or limits, so we use the usual version: read a rectangular matrix of numbers in a clockwise spiral from the top-left corner. The limits (up to 10 rows and 10 columns, values from -100 to 100) and the examples are ours.

Our version is about 95% the same as the reported question.

Given an m x n matrix matrix, return all of its elements in spiral order.

Spiral order starts at the top-left element and goes clockwise: right along the top row, down the right column, left along the bottom row, and up the left column. It then does the same with the part of the matrix that is still left inside, until every element has been listed exactly once.

Function

spiralOrder(matrix: int[][]) → List<Integer>

Examples

Example 1

matrix = [[1,2,3],[4,5,6],[7,8,9]]return = [1,2,3,6,9,8,7,4,5]
matrix
012012314562789

The outer ring, read clockwise from the top-left corner, is 1, 2, 3, 6, 9, 8, 7, 4. Only 5 is left in the middle, so it comes last.

Example 2

matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]return = [1,2,3,4,8,12,11,10,9,5,6,7]
matrix
0123012341567829101112

The outer ring gives 1, 2, 3, 4 along the top, 8, 12 down the right, 11, 10, 9 along the bottom and 5 up the left. What is left inside is the single row 6, 7, read left to right.

Example 3

matrix = [[7],[9],[6]]return = [7,9,6]
matrix
0071926

The matrix is one column. The top row is just 7, and going down the right column adds 9 and 6. There is no separate bottom row or left column to read back.

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 10
  • -100 <= matrix[i][j] <= 100

More Athenahealth interview questions

  • LRU CachePHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
  • Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
  • Game of Life: In-Place Next GenerationGoogle · ONSITE INTERVIEWGoogle interview questions
  • Diagonal Matrix IteratorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Candy Crush Board Until StableBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Game of Life Next GenerationTemporal · ONSITE INTERVIEWTemporal interview questions
  • Minesweeper Board UpdateClay · ONSITE INTERVIEW
  • Minesweeper Board UpdateAirbyte · ONSITE INTERVIEW
See Athenahealth hiring insights
Saved
class Solution {
    public List<Integer> spiralOrder(int[][] matrix) {
        // Write your code here.
    }
}
Checking account…