As reported: Morgan Stanley backend engineer (Java + microservices, 2.4 years of experience), Nov 2025. Offline technical round 2 (with LLD and SQL): print a matrix in spiral order, between questions on SOLID, monolith vs microservices and Kubernetes.
Given an m × n matrix, return all of its elements in spiral order: along the top row to the right, down the right column, back along the bottom row, up the left column, then the same for the inner ring, and so on.
This is LeetCode 54 — Spiral Matrix.
Example 1
[[1,2,3],
[4,5,6], -> [1,2,3,6,9,8,7,4,5]
[7,8,9]]
Example 2
[[1,2,3,4],
[5,6,7,8], -> [1,2,3,4,8,12,11,10,9,5,6,7]
[9,10,11,12]]
Constraints: 1 ≤ m, n ≤ 10; −100 ≤ matrix[i][j] ≤ 100.
Code runner format: one JSON value per line: matrix (LeetCode's test-case format). Implement spiralOrder(matrix); the harness prints the list.