FastPrepS-Shaped Matrix Traversal
Problems/S-Shaped Matrix Traversal

S-Shaped Matrix Traversal

Fox Corporation logoFox Corporation● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

Traverse a nonempty square matrix row by row in an S shape: read row 0 left to right, row 1 right to left, and continue alternating directions.

Return the visited values in order.

Function

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

Examples

Example 1

matrix = [[1]]return = [1]

Case 1 exercises the documented deterministic contract.

Example 2

matrix = [[1,2],[3,4]]return = [1,2,4,3]

Case 2 exercises the documented deterministic contract.

Example 3

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

Case 3 exercises the documented deterministic contract.

Constraints

  • 1 <= matrix.length == matrix[i].length <= 1000.
  • Matrix values are signed 32-bit integers.

More Fox Corporation problems

  • Merge Overlapping IntervalsPHONE SCREEN · Seen Sep 2026
  • Count Communicating ServersPHONE SCREEN · Seen Sep 2026
  • Find a Peak ElementPHONE SCREEN · Seen Sep 2026
See Fox Corporation hiring insights
Saved
class Solution {
    public int[] sShapedTraversal(int[][] matrix) {
        // Write your code here.
    }

}
Checking account…