Skip to content

Latest commit

 

History

History

bomb_enemy

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Problem

Given a 2D grid, each cell is either a wall 'Y', an enemy 'X' or empty '0' (the number zero), return the maximum enemies you can kill using one bomb. The bomb kills all the enemies in the same row and column from the planted point until it hits the wall since the wall is too strong to be destroyed. Note that you can only put the bomb at an empty cell.

Example:

For the given grid

0 X 0 0
X 0 Y X
0 X 0 0

return 3. (Placing a bomb at (1,1) kills 3 enemies)

Solution

Running sum, O(n * m) time and space