FastPrepSpiral Matrix Traversal
Problems/Spiral Matrix Traversal

Spiral Matrix Traversal

Visa logoVisa● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A February 1, 2025 Visa Software Engineer I online assessment report names spiral traversal of a matrix as question 3. It leaves out the direction, the start corner, the limits, and a function signature. Our version uses the usual clockwise spiral from the top-left.

You are given a non-empty rectangular integer matrix.

Return all elements in clockwise spiral order, beginning at the top-left corner. Traverse the top edge, right edge, bottom edge in reverse, and left edge in reverse, then repeat on the remaining inner rectangle.

Function

spiralTraversal(matrix: int[][]) → int[]

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 is 1,2,3,6,9,8,7,4; the remaining center is 5.

Example 2

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

The two-row matrix is consumed entirely by its outer ring.

Constraints

  • 1 <= matrix.length, matrix[i].length <= 1000
  • All rows have the same length.
  • The matrix contains at most 105 elements.
  • -109 <= matrix[i][j] <= 109

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Maximum Diamond SumHudson River Trading · OAHudson River Trading interview questions
  • Robot Navigation Around LasersRoblox · OARoblox interview questions
  • Apply a Reversi MoveAmazon · OA
  • Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
  • Sparse Valid Conv2D From ScratchNVIDIA · OANVIDIA interview questions
  • Apply Matrix OperationsCapital One · OACapital One interview questions
  • Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
  • 2048 Move SimulatorBenchling · OABenchling interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int[] spiralTraversal(int[][] matrix) {
        // Write your code here.
    }

}
Checking account…