FastPrepSpiral Matrix Order
Problems/Spiral Matrix Order

Spiral Matrix Order

Airbnb logoAirbnb● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by a candidate for an Airbnb software engineer internship in the United States, who interviewed around January 2013. The report does not name the round.

The question asks for the values of a 2-D array visited in a clockwise spiral: across the first row from the upper-left corner, down the right side, back along the last row, and on toward the middle. The original wants code that prints the values; here the function returns them as a list. We also allow matrices that are not square, take a ring that is only one row or one column once, and chose the size and value limits and the examples ourselves.

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

You are given an m x n matrix of integers, matrix. Return all of its values in clockwise spiral order.

The spiral starts with the value in the upper-left corner and moves right along the first row to its end. Then it goes down the last column, left along the last row, and up the first column. That finishes the outer ring. The spiral then goes through the next ring inside in the same way, and so on, until every value has been taken exactly once.

If a ring is only one row tall, take its values once from left to right. If it is only one column wide, take its values once from top to bottom.

Function

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

Examples

Example 1

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

The outer ring gives the top row 4, 9, 2, then 7, 6 going down the right column, then 1, 8 going left along the bottom row, then 3 going up the left column. The only value left is the center, 5.

Example 2

matrix = [[1,-2,3],[-4,5,-6],[7,-8,9],[-10,11,-12]]return = [1,-2,3,-6,9,-12,11,-10,7,-4,5,-8]
matrix
01201-231-45-627-893-1011-12

The outer ring gives 1, -2, 3 along the top, -6, 9, -12 down the right column, 11, -10 along the bottom and 7, -4 up the left column. What is left is the middle column of rows 1 and 2 (counting from 0), a ring that is only one column wide, so it is taken once from top to bottom: 5, -8.

Example 3

matrix = [[5],[0],[-5]]return = [5,0,-5]
matrix
005102-5

The matrix is a single column, so its values are taken once from top to bottom.

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 50
  • -1000 <= matrix[i][j] <= 1000

More Airbnb Phone Screen questions

  • Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
  • Text JustificationPHONE SCREEN · Seen Nov 2026
  • Decode and Store StringsPHONE SCREEN · Seen Oct 2026
  • Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
  • Smallest Common RegionPHONE SCREEN · Seen Aug 2026
  • Longest Chain BookingPHONE SCREEN · Seen Aug 2026
  • Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
  • Parse Query StringPHONE SCREEN · Seen May 2026
  • Pacific Atlantic Water FlowPHONE SCREEN · Seen May 2023

Similar questions at other companies

  • 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
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
  • Longest Consecutive Same-Color LineGoogle · PHONE SCREENGoogle interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Diagonal TraverseHive · PHONE SCREENHive interview questions
  • Build a Bird’s-Eye-View Height GridNVIDIA · PHONE SCREENNVIDIA interview questions
  • Multi-Channel Valid ConvolutionTesla · PHONE SCREENTesla interview questions

Interview reports that mention this question

  • Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)

Airbnb interview experiences

  • Airbnb SWE OA: Four-Level Banking System: 1 Experience
  • Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
  • Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
  • Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
  • Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public List<Integer> spiralOrder(int[][] matrix) {
      // Write your code here.
    }
}
Checking account…