Rotate Matrix Over Diagonals

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

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

Capital One's August OA included a matrix rotation problem that looks like a geometry puzzle but plays like a graph traversal. You're rotating elements over diagonals, which means you need to identify which cells belong to the same diagonal, group them, and apply the rotation within those groups. This isn't a typical 90-degree matrix rotation. It's about understanding diagonal structure and movement patterns. StealthCoder can catch the approach in real time if the pattern doesn't click immediately.

Pattern and pitfall

The trick is recognizing that diagonals are invariant paths through a matrix. Cells on the same diagonal share a constant sum (row + column) or difference (row - column), depending on the diagonal direction. Instead of thinking "rotate the whole matrix," think "identify diagonal groups, then rotate elements within each group." BFS helps here because once you pick a starting cell, you can traverse all cells on that diagonal by following adjacency rules within the diagonal constraint. Many candidates start with a 2D rotation library function and waste time. The real pattern is graph traversal on a constrained subgraph. If you blank on the traversal order, StealthCoder gives you the skeleton.

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 Rotate Matrix Over Diagonals 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as rotate image. If you have time before the OA, drill that.

⏵ The honest play

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

Capital One 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.

Rotate Matrix Over Diagonals FAQ

Is this a standard matrix rotation?+

No. Standard rotation spins rows and columns. This rotates elements within diagonals only. Diagonals stay in place, but values shift along them. Think of it as a constraint on the movement space, not a full matrix operation.

Why does the hint say BFS?+

BFS identifies all cells belonging to the same diagonal by treating the matrix as a graph where adjacency is defined by diagonal membership. Starting from one cell, BFS finds all others on that diagonal, then you rotate values within that group.

How do I identify diagonals?+

Cells on the same diagonal share either the same row-column difference (for anti-diagonals) or the same row+column sum (for main diagonals). Use one of these invariants as the grouping key to bucket cells, then sort and rotate.

What's the rotation direction?+

The problem statement wasn't provided, but rotation is typically clockwise or counter-clockwise. The values shift along the diagonal; the diagonal itself doesn't move. Extract values, rotate the list, reinsert in sorted order.

How long should this take?+

10-15 minutes if you see the diagonal grouping trick fast. 25-35 if you code BFS from scratch. Edge cases: single row, single column, 1x1 matrix. Test rotation direction on a small example first.

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

OA at Capital One?
Invisible during screen share
Get it