Transform Binary Matrix
Reported by candidates from Visa's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Visa reported this one in June 2026, and the name makes it sound harder than it is. Transform Binary Matrix is a matrix simulation: rotate an n x n image by 90, 180, or 270 degrees clockwise, then optionally flip vertically, then optionally flip horizontally. No search, no graph, no clever data structure. If you've got an OA invite, this is the kind of problem you want to see. The risk isn't the idea. It's an index slip under a timer. Order of operations matters, and one wrong row or column mapping breaks every test case.
The problem
You are given an n x n binary matrix representing an image. Your task is to transform the image by applying the following operations in order: Rotate the image clockwise by rotation degrees.rotation is one of 90, 180, or 270. If vertical_flip = 1, flip the image vertically, top to bottom. If horizontal_flip = 1, flip the image horizontally, left to right. Return the final transformed binary matrix after all operations are applied. Function transformImage(n: int, rotation: int, vertical_flip: int, horizontal_flip: int, image: int[][]) → int[][] Examples Example 1 n = 3 rotation = 270 vertical_flip = 0 horizontal_flip = 1 image = [[1,0,0],[0,1,1],[0,0,1]] return = [[1,1,0],[0,1,0],[0,0,1]] Original pixels: [[1,0,0], [0,1,1], [0,0,1]] Rotate the image by 270 degrees clockwise: [[0,1,1], [0,1,0], [1,0,0]] vertical_flip is 0, so the image is not flipped vertically. Perform the horizontal flip: [[1,1,0], [0,1,0], [0,0,1]] Note: The screenshot did not show a separate output line. FastPrep calculated this matrix from the visible rotation and flip steps so you can practice with a complete example. 🐥
Reported by candidates. Source: FastPrep
Pattern and pitfall
The hinted pattern says breadth-first-search, but nothing here traverses anything. It's pure simulation. The trick is that every rotation is just 90 degrees applied 1, 2, or 3 times. Write one helper that rotates clockwise: new[i][j] = old[n-1-j][i]. Call it rotation/90 times. Then vertical flip reverses the order of rows. Horizontal flip reverses each row. Apply them in the stated order, because flips and rotations don't commute. The common pitfall is rotating in place and overwriting cells you still need. Build a fresh matrix each step. Check your code against Example 1 by hand: 270 rotation, then horizontal flip. If you blank on the index math during the live OA, StealthCoder is the safety net that reads the problem and hands you the mapping. Complexity is O(n^2) per operation.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Transform Binary Matrix 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as rotate image. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Visa's OA.
Visa reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Transform Binary Matrix FAQ
How hard is the Visa Transform Binary Matrix question really?+
Easy to medium. The logic is simple, but the index math is where people lose time. If you know the clockwise rotation formula and how to reverse rows, it's a short solution. Most failures come from applying operations in the wrong order or mixing up row and column indices.
What's the trick to rotating the matrix clockwise?+
Use new[i][j] = old[n-1-j][i] for a single 90 degree clockwise turn. Equivalent approach: transpose, then reverse each row. For 180 or 270, repeat that helper two or three times. It's easier to get right than writing three separate formulas.
Does this problem actually need BFS?+
No. The hinted pattern is breadth-first-search, but the task is a fixed sequence of matrix transforms. There's no traversal, no connected cells, no shortest path. Treat it as simulation and don't overthink it. Plain nested loops are enough.
What's the difference between vertical and horizontal flip here?+
Vertical flip goes top to bottom, so you reverse the order of rows. Horizontal flip goes left to right, so you reverse the elements inside each row. Apply vertical first if its flag is 1, then horizontal if its flag is 1, after the rotation.
How do I prepare for this in 48 hours?+
Write the clockwise rotation helper from memory twice. Then run Example 1 by hand: rotate 270, skip vertical, flip horizontal, and confirm you get [[1,1,0],[0,1,0],[0,0,1]]. Also test n = 1 and n = 2 so you catch off-by-one mistakes before the assessment.