🚀

Thanksgiving Sale: Use Coupon Code THANKS25 to Get Extra 25% Off.

00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS

Leetcode Problem 2125. Number of Laser Beams in a Bank

2125. Number of Laser Beams in a Bank

Leetcode Solutions

Counting Security Devices and Multiplying Adjacent Rows

  1. Initialize an empty list device_counts to store the count of security devices for each row that has at least one device.
  2. Iterate through each row in the bank array.
    • For each row, count the number of '1's (security devices) and store the count in device_counts if it is greater than zero.
  3. Initialize a variable total_beams to 0, which will store the total number of laser beams.
  4. Iterate through the device_counts list.
    • For each pair of adjacent counts, multiply them and add the result to total_beams.
  5. Return total_beams as the final result.
UML Thumbnail

Iterative Row-by-Row Laser Beam Calculation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...