You are given a 2D grid as a string array where each cell contains either a wall X
, an enemy A
, or is empty 0
(the digit zero). Your task is to determine the highest number of enemies that can be eliminated by placing a single bomb in any empty cell.
The bomb destroys all enemies located in the same row and column as the placement cell, stopping its effect whenever it encounters a wall (walls are indestructible).
Note: You are only allowed to place the bomb on an empty cell.
Example 1: Input: ["0A00", "A0XA", "0A00"] Output: 3 Explanation: For the grid: 0 A 0 0 A 0 X A 0 A 0 0 If you plant the bomb at position (1,1), it will eliminate 3 enemies. Example 2: Input: ["AX00", "00X0", "A000"] Output: 2 Explanation: Placing the bomb at (2,1) will remove 2 enemies (one in the same row and one in the same column).