S-Shaped Matrix Traversal
Reported by candidates from Fox Corporation's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Row 0 left to right, row 1 right to left, repeat. That's the whole spec for the Fox Corporation OA question reported in September 2026, and it's a square matrix up to 1000 by 1000. The hinted pattern says breadth-first-search, but don't buy it. This is a matrix simulation with a direction flip. If you've got an invite and 48 hours, this is one of the friendlier ones. The risk isn't the idea, it's off-by-one slips on the reverse rows. StealthCoder sits invisibly on your screen during the live OA as a safety net if you blank, but you probably won't need it here.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is parity. Loop over rows with index i. If i is even, append the row left to right. If i is odd, append it right to left. That's it. No queue, no visited set, no BFS, so ignore the hint. Time is O(n^2) because you touch every cell once, and the output array holds n^2 values. With n up to 1000 that's one million integers, so preallocate the result or use a growing list, and don't build a new reversed copy of every odd row if you want to stay tidy. The common pitfall is the reverse loop bounds. Start at n-1 and stop at 0 inclusive. Check example 2 by hand: [[1,2],[3,4]] gives [1,2,4,3]. Values are signed 32-bit, but you're only copying them, so overflow never comes up. If you freeze on the loop bounds during the live OA, StealthCoder is the hedge that hands you the clean version.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill S-Shaped Matrix Traversal cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Fox Corporation's OA.
Fox Corporation reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
S-Shaped Matrix Traversal FAQ
How hard is the S-shaped matrix traversal really?+
Easy. It's a single pass with a direction flip on odd rows. The Fox Corporation version is a square matrix, so there are no ragged rows or empty inputs to worry about. Most of the time goes to getting the reverse loop bounds right, not to the idea.
What's the trick to solving it?+
Use row parity. Even rows go left to right, odd rows go right to left. Append values to one result array as you go. You don't need extra state beyond the row index and the column loop.
Is BFS the right pattern even though it's hinted?+
No. Nothing here needs a queue or neighbor exploration. It's matrix simulation with a fixed visiting order. Writing BFS adds complexity and bug surface for zero benefit. Plain nested loops run in O(n^2) and are easiest to verify.
What edge cases should I test?+
Test the 1x1 matrix, which returns [1]. Test the 2x2 case, which returns [1,2,4,3], to confirm the reverse row. Then test a 3x3 to confirm the direction flips back on row 2. Also consider n = 1000 for output size and speed.
How do I prepare for this in 48 hours?+
Write it from scratch twice, once with an if on row parity and once with a toggled boolean flag. Trace the 3x3 example by hand. Then spend remaining time on other matrix traversal variants like spiral and diagonal, since the same assessment may mix them.