Tap here to switch tabs
Problem
Submissions

Problem: Number of Laser Beams in a Bank

med
30 min
Try to solve the Number of Laser Beams in a Bank problem.

Statement

You are given a 00 indexed 22D binary string array bank representing the floor plan of a bank, where $'0'$ represents an empty cell and $'1'$ represents a cell containing a security device.

A laser beam connects two security devices if and only if both conditions are satisfied:

  1. The two devices are located on two distinct rows, r1r_1 and r2r_2, where r1<r2r_1 < r_2.

  2. For every row ii strictly between r1r_1 and r2r_2 (r1<i<r2r_1 < i < r_2), there are no security devices.

Laser beams function independently, meaning beams do not block or interfere with one another.

Return the total number of laser beams in the bank.

Constraints:

  • m ==== bank.length

  • n ==== bank[i].length

  • 1≤1 \leq m, n ≤500\leq 500

  • bank[i][j] is either $'0'$ or $'1'$

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Laser Beams in a Bank

med
30 min
Try to solve the Number of Laser Beams in a Bank problem.

Statement

You are given a 00 indexed 22D binary string array bank representing the floor plan of a bank, where $'0'$ represents an empty cell and $'1'$ represents a cell containing a security device.

A laser beam connects two security devices if and only if both conditions are satisfied:

  1. The two devices are located on two distinct rows, r1r_1 and r2r_2, where r1<r2r_1 < r_2.

  2. For every row ii strictly between r1r_1 and r2r_2 (r1<i<r2r_1 < i < r_2), there are no security devices.

Laser beams function independently, meaning beams do not block or interfere with one another.

Return the total number of laser beams in the bank.

Constraints:

  • m ==== bank.length

  • n ==== bank[i].length

  • 1≤1 \leq m, n ≤500\leq 500

  • bank[i][j] is either $'0'$ or $'1'$