Reported October 2022
ZipRecruitermatrix

Square Matrix Rotation and Reflections

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

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

The mistake that sinks a first attempt on this ZipRecruiter OA, reported in October 2022, is physically transforming the matrix once per query. It looks like a plain matrix problem: apply rotations and diagonal reflections in order and return the result. The hinted pattern is breadth-first-search, but nothing here is a graph. It's matrix manipulation with a composition trick. If queries get long, the naive loop gets slow and messy. If you blank on the math, StealthCoder can run invisibly during the live assessment and hand you a clean solution as a safety net.

The problem

Apply query codes to a square matrix in order: 0 rotates 90 degrees clockwise, 1 reflects across the main diagonal, and 2 reflects across the secondary diagonal. Return the final matrix.

Function
applyMatrixTransforms(matrix: int[][], queries: int[]) → int[][]

Examples
Example 1
matrix = [[1,2],[3,4]]
queries = [0]
return = [[3,1],[4,2]]
One clockwise quarter-turn is applied.
Example 2
matrix = [[1,2],[3,4]]
queries = [1]
return = [[1,3],[2,4]]
Main-diagonal reflection transposes the matrix.

Constraints
1 <= n <= 200
Every query is 0, 1, or 2.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: every query is one of four-fold symmetries of the square (the dihedral group). Rotation by 90 clockwise, transpose, and anti-transpose are all just index mappings. So track the state as a small transform, like a rotation count plus a flip flag, and compose each query into it in O(1). Then build the output matrix once at the end in O(n^2). The pitfall is applying each query to the full matrix, which costs O(n^2) per query and invites in-place bugs. Another pitfall is mixing up the secondary diagonal: it maps (i,j) to (n-1-j, n-1-i). Check your composition against Example 1 and Example 2 before submitting. Even simpler and safe: simulate with a fresh copy per query if the query count is small. StealthCoder is the hedge if you freeze on the composition rules during the live OA, since it reads the problem on screen and gives you the code.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Square Matrix Rotation and Reflections 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

ZipRecruiter reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Square Matrix Rotation and Reflections FAQ

What's the real pattern for this ZipRecruiter matrix problem?+

It's matrix transformation, not graph search, despite the breadth-first-search hint. Each query is an index mapping on a square grid. Rotation is transpose plus row reversal, and the diagonal reflections are transpose-like swaps. Know those three mappings cold and you're most of the way there.

How do I avoid the first-attempt mistake?+

Don't mutate the matrix in place while reading from it. Either write into a new n by n matrix per query or compose the transforms first and apply once. Test with the two examples, especially the 90 degree clockwise case giving [[3,1],[4,2]].

How do I rotate 90 degrees clockwise quickly?+

Transpose the matrix, then reverse each row. Check it on [[1,2],[3,4]]: transpose gives [[1,3],[2,4]], reversing rows gives [[3,1],[4,2]], which matches Example 1. In index terms, new[i][j] = old[n-1-j][i].

How do I reflect across the secondary diagonal?+

Map cell (i,j) to (n-1-j, n-1-i). That's the anti-transpose. A handy check: it equals a clockwise rotation followed by a main-diagonal reflection, or a transpose followed by a 180 degree rotation. Verify on a 2 by 2 by hand before coding.

How should I prep for this in 48 hours?+

Write the three transforms from memory on a 3 by 3 grid. Then code the version that applies each query to a fresh copy, since n is at most 200. Only optimize by composing transforms if you have time. Correctness on small grids beats a clever solution that's wrong.

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

OA at ZipRecruiter?
Invisible during screen share
Get it