FastPrepBomb Enemy Best Coordinates

Bomb Enemy Best Coordinates

SambaNova Systems logoSambaNova Systems● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

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.

More SambaNova Systems problems

See SambaNova Systems hiring insights
public int[][] bestBombCells(String[] grid) {
    // write your code here
}
grid["0E00","E0WE","0E00"]
expected[[1,1]]
Checking account…