Number of Laser Beams in a Bank - Problem
Bank Security Laser System
You're working as a security consultant for a high-tech bank that uses an innovative laser beam security system. The bank's floor plan is represented as a 2D grid where each cell can either be empty (
The laser system works with these rules:
• Laser beams form between security devices on different rows
• A beam can only exist if there are no security devices in any row between the two connected devices
• Each device on row A connects to every device on the next valid row B
Your task is to calculate the total number of laser beams in this security system.
Example: If row 1 has 3 devices and row 4 has 2 devices (with rows 2-3 empty), there will be
You're working as a security consultant for a high-tech bank that uses an innovative laser beam security system. The bank's floor plan is represented as a 2D grid where each cell can either be empty (
'0') or contain a security device ('1').The laser system works with these rules:
• Laser beams form between security devices on different rows
• A beam can only exist if there are no security devices in any row between the two connected devices
• Each device on row A connects to every device on the next valid row B
Your task is to calculate the total number of laser beams in this security system.
Example: If row 1 has 3 devices and row 4 has 2 devices (with rows 2-3 empty), there will be
3 × 2 = 6 laser beams between them. Input & Output
example_1.py — Basic Grid
$
Input:
["011001", "000000", "010100", "001000"]
›
Output:
8
💡 Note:
Row 0 has 3 devices, Row 2 has 2 devices, Row 3 has 1 device. Laser beams: 3×2=6 (between rows 0,2) + 2×1=2 (between rows 2,3) = 8 total.
example_2.py — No Beams Possible
$
Input:
["000", "111", "000"]
›
Output:
0
💡 Note:
Only row 1 has devices. Since laser beams require devices on different rows, and there's only one row with devices, no beams can be formed.
example_3.py — All Rows Have Devices
$
Input:
["11", "01", "10"]
›
Output:
3
💡 Note:
Row 0: 2 devices, Row 1: 1 device, Row 2: 1 device. Beams: 2×1=2 (rows 0,1) + 1×1=1 (rows 1,2) = 3 total.
Constraints
- m == bank.length
- n == bank[i].length
- 1 ≤ m, n ≤ 500
- bank[i][j] is either '0' or '1'
- Each row contains at least one character
Visualization
Tap to expand
Understanding the Visualization
1
Scan Each Level
Count how many laser projectors are on each stage level
2
Skip Empty Levels
Levels with no projectors don't affect beam formation
3
Connect Adjacent Levels
Each projector on level A connects to each projector on the next occupied level B
4
Calculate Total Beams
Multiply projector counts: Level A count × Level B count
Key Takeaway
🎯 Key Insight: We only need to track consecutive 'active' levels and multiply their projector counts - no need to check individual projector pairs!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code