Flipping Matrix
Reported by candidates from Zomato's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Zomato reported this one in July 2026, and the trap is that it looks like a search problem when it isn't. Flipping Matrix hands you a 2N x 2N grid and lets you reverse any row or column in any order. Most people see "any order, any number of times" and start thinking BFS over matrix states. That blows up fast. The real answer is a greedy pick per cell, and it runs in O(N^2). If you blank on that during the OA, StealthCoder is the safety net that reads the screen and gives you the solution without the proctor seeing anything.
The problem
You are given a 2N x 2N matrix of integers. You may reverse any row or any column any number of times and in any order. Return the maximum possible sum of the upper-left N x N submatrix, covering rows 0 through N - 1 and columns 0 through N - 1. Function maxUpperLeftSubmatrixSum(matrix: int[][]) → int Examples Example 1 matrix = [[112,42,83,119],[56,125,56,49],[15,78,101,43],[62,98,114,108]] return = 414 For each target cell in the upper-left quadrant, choose the largest value among the four cells that can be moved there by row and column reversals. The chosen values are 119, 114, 56, and 125, for a total of 414. The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is symmetry. For any cell (i, j) in the upper-left N x N quadrant, a reversal can only bring in values from three mirror positions: (i, 2N-1-j), (2N-1-i, j), and (2N-1-i, 2N-1-j). So each target cell has exactly four candidates, and you can independently pick the max of those four. Sum those maxes across the quadrant. Check it on the sample: 119, 114, 56, 125 gives 414. The pitfall is the hinted BFS idea. Exploring reversal states is exponential and pointless. The other common bug is the mirror index, using N-1-i instead of 2N-1-i. Off-by-one there silently gives wrong sums on small cases. Loop i and j from 0 to N-1, take the max of four, add it up. StealthCoder is your hedge in the live OA if the symmetry argument escapes you under pressure.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Flipping 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as maximum matrix sum. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Zomato's OA.
Zomato 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.
Flipping Matrix FAQ
What's the trick in Flipping Matrix?+
Each cell in the upper-left quadrant can be swapped with exactly three mirror cells, so four candidates total. Reversals let you place any of the four there independently. Take the max of the four for each quadrant cell and sum. No simulation needed.
Is BFS actually needed for this problem?+
No. The hinted pattern points at state search, but the state space is huge and unnecessary. The problem collapses to a greedy max over four mirrored positions per cell. It's a matrix and greedy problem, solved in two nested loops.
What are the mirror indices for cell (i, j)?+
With size 2N, the four candidates are (i, j), (i, 2N-1-j), (2N-1-i, j), and (2N-1-i, 2N-1-j). Mixing up 2N-1 with N-1 is the most common bug. Test it against the sample that sums to 414.
What's the time and space complexity?+
Time is O(N^2) since you visit each of the N x N quadrant cells once and check four values. Space is O(1) extra because you only keep a running sum. You don't need to modify or copy the matrix.
How do I prepare for this in 48 hours?+
Hand-trace the 4x4 sample until the four-candidate idea feels obvious. Then write the loop from memory and test a 2x2 case. Zomato reported this in July 2026, so expect similar matrix-symmetry questions. Focus on index math, not search.