FastPrepSpiral Matrix
Problems/Spiral Matrix

Spiral Matrix

Zillow logoZillow● MediumFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow in 2022 by two candidates: a Software Development Engineer intern in the United States in November, and an iOS engineer in New York in September. Both reports name the task spiral matrix. The iOS candidate got it as the one coding problem of a phone interview, before an onsite made up of iOS rounds. The intern met it in the second round, which had two interviews and was the last step of their process; it came up in the second of those interviews, next to behavioral questions. We read that final two-interview round as the onsite stage. The intern adds that this interviewer kept steering them toward another method.

The reports do not say which method that interviewer wanted, how the matrix is passed in, or which way the walk turns. These choices are ours, taken from the well-known version of this task: the function spiralOrder gets a rectangular matrix of integers and returns its values in the order of a clockwise walk that starts at the top-left corner and moves inward ring by ring. The size and value limits are ours as well.

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

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

Spiral order starts at the top-left corner and walks clockwise around the outer edge: right along the top row, down the right column, left along the bottom row, then up the left column. The walk then does the same on the next ring inside and keeps moving inward until every value has been visited exactly once.

Function

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

Examples

Example 1

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

The outer ring comes first: 1, 2, 3, 4 along the top row, 5 and 6 down the right column, 7, 8, 9 back along the bottom row, and 10 up the left column.

Only 11 and 12 in the middle row are left. They form the next ring and are read left to right. The values in this matrix were placed so that the answer counts from 1 to 12.

Example 2

matrix = [[5,-1],[0,7],[3,-4],[8,2]]return = [5,-1,7,-4,2,8,3,0]
matrix
0105-110723-4382

The top row gives 5 and -1. Going down the right column gives 7, -4 and 2. Going left along the bottom row gives 8, and going up the left column gives 3 and 0.

That covers all 8 values, so no inner ring is left.

Example 3

matrix = [[6],[-3],[0]]return = [6,-3,0]
matrix
0061-320

The matrix has one column. The top row gives 6, and the walk down the right column gives -3 and 0.

Every value is now taken, so the walk does not come back up the same column.

Constraints

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

More Zillow Onsite Interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Count Duplicate CharactersONSITE INTERVIEW · Seen Oct 2020
  • Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
  • Find Median from Data StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2018
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Tic-Tac-Toe Winner on a Huge BoardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2016
  • Most Frequent Three-Page SequencesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2016
  • Maximum Path Sum in a GridONSITE INTERVIEW · Seen Apr 2016

Similar questions at other companies

  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
  • Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
  • Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
  • Longest Consecutive Same-Color LineGoogle · PHONE SCREENGoogle interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public List<Integer> spiralOrder(int[][] matrix) {
        // Write your code here.
    }
}
Checking account…