2125. Number of Laser Beams in a Bank
Intuition\nThe problem seems to involve counting the number of beams formed based on the floors in a bank. The beams are formed by the presence of non-zero digi
# Intuition\nThe problem seems to involve counting the number of beams formed based on the floors in a bank. The beams are formed by the presence of non-zero digits in each floor. The count of beams formed on a floor is determined by the sum of non-zero digits on that floor.\n\n# Approach\nThe provided code iterates through each floor in the bank and calculates the count of beams on each floor based on the sum of non-zero digits. It accumulates the total count by multiplying the count of beams on the current floor with the count of beams on the previous floor. The final result is the total count of beams formed in the bank.\n\n# Complexity\n- Time complexity: O(n * m), where n is the number of floors in the bank and m is the average number of digits in a floor.\n- Space complexity: O(1), as the algorithm uses a constant amount of space regardless of the input size.\n\n# Code\n```javascript\n/**\n * @param {string[]} bank\n * @return {number}\n */\nvar numberOfBeams = function(bank) {\n    let prevCount = 0, totalCount = 0;\n\n    // Iterate through each floor in the bank\n    for (const floor of bank) {\n        // Calculate the count of beams on the current floor\n        const count = floor.split(\'\').reduce((acc, c) => acc + parseInt(c), 0);\n        \n        // If there are non-zero beams on the current floor\n        if (count > 0) {\n            // Accumulate the total count by multiplying the count of beams on the current floor\n            // with the count of beams on the previous floor\n            totalCount += prevCount * count;\n            // Update the previous count to the count of beams on the current floor\n            prevCount = count;\n        }\n    }\n\n    // Return the total count of beams formed in the bank\n    return totalCount;\n};\n\n```\n\nThe code appears to be a valid implementation for counting the number of beams in the given bank. However, it\'s crucial to note that the correctness of the solution depends on the problem requirements and constraints, which are not explicitly provided in the code or description.
['JavaScript']