Reported September 2026
Ubersimulation

Zigzag Board Adjacent Swaps

Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Uber OA. Under 2s to a working solution.
Founder's read

The Uber OA reported in September 2026 looks like a board puzzle, but it's really a flattened array with a sorting rule. "Zigzag Board Adjacent Swaps" hands you an n x n grid and asks for the exact swap sequence that sorts it along a snake path. If you read it as a 2D problem you'll waste time. Flatten the snake, then run a deterministic insertion-style bubble. The output order matters, so one wrong loop direction fails every test. If you blank mid-assessment, StealthCoder runs invisibly as a safety net, but the logic here is short enough to own tonight.

The problem

An n x n board contains every integer from 1 through n^2 exactly once. The target board lists values in increasing zigzag row order: left to right on row 0, right to left on row 1, and so on.
Use the zigzag cells themselves as one path. For each target path position from first to last, locate its required value later on the path and repeatedly swap it with the preceding path cell until it reaches the target position.
Return the resulting deterministic swap sequence. Each swap is [row1, column1, row2, column2]. Consecutive path cells are always horizontally or vertically adjacent.

Function
zigzagSwaps(board: int[][]) → int[][]

Examples
Example 1
board = [[1,3],[2,4]]
return = [[1,0,1,1],[1,1,0,1]]
Value 2 moves backward along the zigzag path from (1,0) to (1,1) and then to (0,1).
Example 2
board = [[1,2],[4,3]]
return = []
The board already matches increasing zigzag order.

Constraints
1 <= n = board.length = board[i].length <= 20.
The board contains every integer from 1 through n^2 exactly once.
The returned sequence contains at most n^2(n^2-1)/2 swaps.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: build the zigzag path as a list of (row, col) cells. Even rows go left to right, odd rows go right to left. Read the board values along that path into a flat array. Then for each target position i from 0 to n^2-1, the required value is i+1. Find where it sits at index j >= i, and while j > i, emit the swap [path[j-1], path[j]] in the order (earlier cell first, then later cell is how the example reads, so check Example 1 carefully) and swap the values in your array. The edge case that breaks a naive solution is the coordinate order and direction. The example shows the swap listed with the cell at j first, then j-1. Match that exactly. Another pitfall is recomputing positions from the 2D board instead of the flat array after swaps. Max swaps is n^2(n^2-1)/2, so n=20 stays tiny. If the output order trips you live, StealthCoder is the hedge.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Zigzag Board Adjacent Swaps 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Uber's OA.

Uber reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Zigzag Board Adjacent Swaps FAQ

How hard is Zigzag Board Adjacent Swaps really?+

Easy to medium. There's no clever algorithm. It's flattening the snake path and doing insertion-style adjacent swaps. The difficulty is following the spec exactly, especially swap output order and the zigzag direction on odd rows.

What's the trick to solving it fast?+

Convert the board into a 1D list of cells following the zigzag path. Then treat it as sorting by adjacent swaps. For each target index, find the needed value later in the list and bubble it backward, recording each swap as you go.

Which edge case do people miss?+

The order of coordinates inside each swap. Example 1 lists the cell where the value currently sits first, then the preceding cell. Flip that and you fail even though the board ends up sorted. Also handle already-sorted boards by returning an empty list.

Do I need to worry about performance at n = 20?+

No. That's 400 cells and at most about 80,000 swaps. A scan to find each value plus bubbling backward is fine. Don't over-optimize with fancy structures. Correctness of the sequence is what's graded.

How do I prepare for this in 48 hours?+

Practice flattening a grid along a snake path, then write an insertion-sort variant that records every swap. Test on both examples by hand, including the empty-result case. Check output order against Example 1 before you submit anything.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Uber.

OA at Uber?
Invisible during screen share
Get it