(O(n*m)⏱️) JAVA☕ PYTHON🐍 JAVASCRIPT💛 Linear Solution✅
Github - https://github.com/VishnuThangaraj \uD83D\uDE3A\n\n\n# Intuition\uD83E\uDDE0\n Describe your first thoughts on how to solve this problem. \nCalculate t
Github - https://github.com/VishnuThangaraj \uD83D\uDE3A\n\n\n# Intuition\uD83E\uDDE0\n<!-- Describe your first thoughts on how to solve this problem. -->\nCalculate the count of "1"(laser\'s) in Each String and multiply with the count of laser\'s in the previous string. Then, update the total laser\'s and previous laser count accordingly.\n\n# Approach\u26A1\n<!-- Describe your approach to solving the problem. -->\n1. Initialize variables `total` and `previousLasers` (lasers in previous string).\n2. Iterate the Each String and calculate the count of lasers present the in current row to a variable `current`.\n3. If No lasers found in the `current` String, Continue.\n4. If lasers found in the `current` String, update the `total` variable and modify `previousLasers` count as `current` row laser count.\n5. Return the `total` variable.\n\n# Complexity\u231B\n- Time complexity: `O(n*m)`, where n is the size of the input array. and m is the size of the string.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(1)`, as we use a constant amount of space for variables.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\uD83D\uDCBB\n``` Java\u2615 []\nclass Solution {\n    public int numberOfBeams(String[] bank) {\n        int total = 0, previousLasers = 0;\n\n        for(String row : bank){\n            int current = 0; // Calculate number of \'1\' in current Row\n            for(char cell : row.toCharArray())\n                current += cell - \'0\';\n\n            // continue if No lasers found in the current Row\n            if(current == 0) continue; \n\n            total += previousLasers * current;\n            previousLasers = current;\n        }\n\n        return total;\n    }\n}\n```\n``` Python\uD83D\uDC0D []\nclass Solution:\n    def numberOfBeams(self, bank: List[str]) -> int:\n        total, previousLasers = 0, 0\n\n        for row in bank:\n            current = row.count("1")\n\n            # continue if No lasers found in the current Row\n            if current == 0: \n                continue\n\n            total += previousLasers * current\n            previousLasers = current\n\n        return total\n```\n``` Javascript\uD83D\uDC9B []\nvar numberOfBeams = function(bank) {\n    let total = 0, previousLasers = 0;\n\n        for (row of bank){\n            current = row.split("1").length - 1;\n\n            // continue if No lasers found in the current Row\n            if (current == 0) continue;\n\n            total += previousLasers * current\n            previousLasers = current\n        }\n        \n        return total;\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/0e50660c-6b3b-4215-ae3c-e46ba31349a0_1704247256.5081427.jpeg)\n
['Math', 'String', 'Java', 'Python3', 'JavaScript']