Reconstruct a 2-Row Binary Matrix
A medium-tier problem at 48% community acceptance, tagged with Array, Greedy, Matrix. Reported in interviews at Grab and 1 others.
You're given upper and lower row constraints and need to place binary values so each column's sum matches a target. It's a medium-difficulty grid-filling problem that Grab and American Express have both asked. The greedy instinct feels right at first, but the trick is sequencing your decisions so you don't paint yourself into a corner. About half of candidates get it on first attempt. If you hit this live and blank on the order of operations, StealthCoder surfaces a working solution invisible to the proctor while you think.
Companies that ask "Reconstruct a 2-Row Binary Matrix"
Reconstruct a 2-Row Binary Matrix is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe core pattern is greedy placement with forward validation. You iterate column by column and try to assign binary values to each row, but you can't just fill greedily without checking if remaining columns can still satisfy the row sums. The trick: after each column assignment, verify that the leftover row sums are feasible given the remaining columns. If upper and lower rows have been assigned values and their remaining sums exceed remaining columns, that assignment fails. Most stumbles happen here, trying to commit to a placement without confirming the tail is still solvable. Array and Matrix topics mean you're working with the 2D structure directly. The Greedy category confirms you're meant to make locally optimal choices, but with backtracking or lookahead. When the obvious greedy approach doesn't work, StealthCoder hedges the live OA.
Pattern tags
You know the problem.
Make sure you actually pass it.
Reconstruct a 2-Row Binary Matrix recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Reconstruct a 2-Row Binary Matrix interview FAQ
Is this problem about backtracking or pure greedy?+
It's greedy with validation. You fill each column by trying assignments, but you must check that remaining row sums stay feasible after each choice. If they don't, backtrack. Most solutions use one forward pass without deep recursion because the constraints are tight enough to guide the greedy path.
What's the main pitfall candidates hit?+
Assigning a column without verifying the remaining sum can be satisfied by remaining columns. You greedily assign 1 to upper, then realize lower now needs more 1s than columns left. Always compute residual sums and column count before committing.
Why is acceptance rate only 47 percent?+
The validation step is non-obvious. Many jump to a greedy loop without the lookahead check. Edge cases around zero sums and full rows also catch submissions. It's a straightforward idea that requires careful implementation.
Does this appear frequently at other companies?+
It's asked less often than classic array problems, but Grab and American Express confirm it's in rotation. Medium-difficulty grid problems like this show up in rounds targeting practical optimization and constraint satisfaction skills.
How does the Greedy topic connect to the solution?+
Greedy is the strategy: commit to column assignments that are locally valid and globally feasible. The Matrix and Array topics just describe the data structure you're working in. The real work is the greedy decision logic with forward-checking.
Want the actual problem statement? View "Reconstruct a 2-Row Binary Matrix" on LeetCode →