Best Cell for One Blast That Clears the Most Spam Bots

Last updated: November 29, 2026

Quick Overview

A grid contains walls 'W', spam bots 'E' and empty cells '0'. A blast placed on an empty cell clears every bot in the same row and column until a wall blocks it; return the maximum number of bots one blast can clear.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A grid contains walls 'W', spam bots 'E' and empty cells '0'. A blast placed on an empty cell clears every bot in the same row and column until a wall blocks it; return the maximum number of bots one blast can clear.

A Meta onsite question about avoiding repeated scans with cached segment counts. It can be framed as integrity tooling that removes clusters of fake accounts arranged on a grid. The interviewer looks for the trick of recomputing a row or column count only when entering a new wall-delimited segment.

What the Interviewer Expects
  • Give the O(RC(R + C)) brute force first
  • Observe that a row segment's count is shared by every cell in that segment
  • Recount the row only at column 0 or right after a wall
  • Keep a per-column cache that is refreshed after walls
  • Achieve O(RC) amortized time
Key Topics to Cover
Dynamic programming
Caching
Matrix
Segments
Amortized analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if the blast also traveled diagonally?
  • How would you handle the grid changing between queries?
  • Return all cells that achieve the maximum.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Grid up to 500 x 500.
  • Blasts may only be placed on '0' cells and stop at walls.
  • Return the largest count of bots cleared....
High-Level Design

For a cell, the bots it hits along its row are exactly the bots in its wall-delimited row segment, and the same holds for its column. All cells in one segment share that count. So while scanning row-m...


Submit Your Answer
Markdown supported