Read a Matrix in Spiral Order
Updated
Problem statement
You are given an m x n integer matrix. Return all of its values in spiral order: start at the top-left cell, go right along the top row, down the right column, left along the bottom row and up the left column, then repeat the same clockwise walk on the part that is left inside, until every cell has been read exactly once.
Function
spiralRead(matrix: int[][]) → List<Integer>Examples
Example 1
matrix = [[4,-1,7],[0,9,2]]return = [4,-1,7,2,9,0]Go right along the top row (4, -1, 7), down the last column (2), then left along the bottom row (9, 0). Every value is used once: [4,-1,7,2,9,0].
Example 2
matrix = [[5],[8],[3]]return = [5,8,3]One column: the walk simply goes down it: [5,8,3].
Example 3
matrix = [[3,8,1],[6,2,7],[9,4,5]]return = [3,8,1,7,5,4,9,6,2]The outer ring gives 3, 8, 1, 7, 5, 4, 9, 6. The center 2 comes last: [3,8,1,7,5,4,9,6,2].
Constraints
1 <= matrix.length, matrix[i].length <= 50, and all rows have the same length-1000 <= matrix[i][j] <= 1000
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
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