The Number of Laser Beams in a Bank problem gives you a bank security system represented as a grid of strings. Each '1' is a security device. Laser beams form between devices in adjacent occupied rows (rows with at least one device). The number of beams between two adjacent occupied rows = (devices in row A) × (devices in row B). Sum all such products. This coding problem requires counting 1s per row and multiplying consecutive non-empty rows.
Meta, Amazon, and Adobe ask this as a clean array and matrix problem that tests the ability to identify the key observation (skip empty rows, multiply adjacent occupied row counts). The array, matrix, math, and string interview pattern is applied directly.
Row count scan with adjacent product. Count the number of '1's in each row. Filter out rows with 0 devices (empty rows). For each consecutive pair of non-empty rows, multiply their device counts and add to the total.
Bank:
"011001"
"000000"
"010100"
"001000"
Row 0: 3 devices. Row 1: 0 (skip). Row 2: 2 devices. Row 3: 1 device. Non-empty rows: [3, 2, 1]. Beams: 32 + 21 = 6+2 = 8.
This problem decomposes cleanly into two steps: (1) extract device counts per row, filtering empties; (2) compute adjacent pair products. Practice extracting data from 2D grid rows, then applying array computations on the extracted data. This two-step decomposition — extract then compute — is a general strategy for matrix problems that have row/column structure. Getting comfortable with string.count('1') for counting characters in a row is useful for grid string problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Divisibility Array of a String | Medium | Solve | |
| Rotate Image | Medium | Solve | |
| Perform String Shifts | Easy | Solve | |
| Number Of Corner Rectangles | Medium | Solve | |
| Magic Squares In Grid | Medium | Solve |