m × n table grid. Each cell holds one character: 'W' is a wall, 'E' is a target, and '0' is an empty cell.
You may place a laser turret in one empty cell. It fires in all four directions at once: up, down, left and right. A beam passes through targets, hitting every one on its way, but stops at the first wall (which it cannot destroy) or at the edge of the board.
Return the largest number of targets a single shot can hit. If there is no empty cell, return 0.grid=[["E", "0", "E"], ["0", "W", "E"], ["E", "0", "0"]] → 3
A turret in the bottom-right corner (row 2, column 2) hits the two targets above it in the last column and the target at the start of its row: 3 in total.
grid=[["E", "W", "0", "E"]] → 1
The only empty cell sees the target to its right; the one on the left is behind a wall.
grid=[["E", "E"], ["W", "E"]] → 0
There are no empty cells, so the turret cannot be placed and the answer is 0.
grid have the same length ngrid[i][j] is one of 'W', 'E', '0'grid=[["E", "0", "E"], ["0", "W", "E"], ["E", "0", "0"]]
3
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.