Bomb Enemy Best Coordinates
Reported by candidates from SambaNova Systems's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The SambaNova Systems OA reported in June 2022 hands you a grid of E, W, and 0 characters and asks where a bomb kills the most enemies. The twist is the return value. You don't give back one best cell, you give back every tied coordinate, sorted by row then column. And a cell with zero kills still counts if nothing beats it. It's the classic bomb enemy problem with a tie-collection layer on top. If you blank on the row and column bookkeeping, StealthCoder is the safety net running invisibly during the live OA.
The problem
A grid contains enemies E, walls W, and empty cells 0. A bomb may be placed in one empty cell and kills every enemy in the same row and column until a wall blocks the direction. Return every zero-based coordinate [row, column] that achieves the maximum kill count, ordered by row and then column. If there is no empty cell, return an empty array. Cells with a maximum of zero are still returned. Function bestBombCells(grid: String[]) → int[][] Examples Example 1 grid = ["0E00","E0WE","0E00"] return = [[1,1]] The center-left empty cell reaches three enemies. Example 2 grid = ["0"] return = [[0,0]] The only empty cell is the maximum even though it kills zero. Example 3 grid = ["EEE"] return = [] There is no legal bomb cell. Constraints 1 <= rows, columns <= 500. The grid is rectangular and contains only E, W, and 0.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is caching segment counts instead of rescanning. Walk the grid row by row. At the start of each row, and right after every wall, count enemies until the next wall and store that as the current row total. Do the same for columns, keeping one running total per column that you refresh whenever the cell above is a wall or you're on row zero. At each empty cell, kills equals rowTotal plus colTotal. That's O(rows x cols) with O(cols) extra space. The pitfalls are all in the output. Track the max and reset your list when you find a bigger value, append on ties, and start the max at -1 so zero-kill cells register. Scanning in row-major order gives you the required sort for free. If no empty cell exists, return an empty array. Example 3 tests exactly that. If the segment resets feel slippery under a clock, StealthCoder can talk you through them live.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Bomb Enemy Best Coordinates 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass SambaNova Systems's OA.
SambaNova Systems reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Bomb Enemy Best Coordinates FAQ
What's the trick to the SambaNova bomb enemy problem?+
Cache the enemy count for the current row segment and each column segment. Recompute only after a wall or at a grid edge. Then every empty cell is just rowTotal plus colTotal. That cuts the brute force from O(n^3) style rescans to a single pass.
How is this different from the standard LeetCode bomb enemy?+
The standard version returns one maximum number. This one returns every coordinate that ties for the max, in row then column order. It also counts zero-kill cells as valid answers, so your initial max can't be zero-based in a way that hides them.
What edge cases should I test before submitting?+
Test a single 0 cell, which should return [[0,0]]. Test a grid with no empty cells, like EEE, which returns an empty array. Test walls that split a row or column, and a grid where all empty cells tie. Those cover the reset and tie logic.
Do I need to sort the result?+
No, if you iterate row by row and left to right, you append coordinates already in the required order. Just don't reorder them. Reset the list only when you find a strictly greater kill count, and append on equal counts.
How do I prepare for this in 48 hours?+
Write the segment-caching solution once from memory on a small grid. Then handle the tie list and the no-empty-cell case. Practice tracing Example 1 by hand to confirm the center-left cell gives three. That's enough for this pattern, since it's a matrix scan with running counts.