[Java/Python 3] Product of neighboring row devices number.
Q & A\n\nQ1: How we got to know that we are required to do product of adjacent rows with count of 1s? \nA1: According to the problem:\nThere is one laser beam b
**Q & A**\n\nQ1: How we got to know that we are required to do product of adjacent rows with count of 1s? \nA1: According to the problem:\nThere is one laser beam between any two security devices if both conditions are met:\n\n1. The two devices are located on two different rows: r1 and r2, where r1 < r2.\n2. For each row i where r1 < i < r2, there are no security devices in the ith row.\n\n**End of Q & A**\n\n----\n\nGet rid of empty rows and then sum the product of each pair of neighbors.\n```java\n    public int numberOfBeams(String[] bank) {\n        int cnt = 0, prev = 0;\n        for (String devs : bank) {\n            // devs.chars() cost more than O(1) space. - credit to @bharathkalyans.\n            // int cur = devs.chars().map(i -> i == \'1\' ? 1 : 0).sum();\n            int cur = 0;\n            for (int i = 0; i < devs.length(); ++i) {\n                cur += devs.charAt(i) == \'1\' ? 1 : 0;\n            }\n            cnt += prev * cur;\n            if (cur > 0) {\n                prev = cur;\n            }\n        }\n        return cnt;\n    }\n```\n```python\n    def numberOfBeams(self, bank: List[str]) -> int:\n        cnt = prev = 0\n        for devs in bank:\n            cur = devs.count(\'1\')\n            cnt += cur * prev\n            if cur > 0:\n                prev = cur\n        return cnt\n```\n**Analysis:**\n\nTime: `O(n)`, space: `O(1)`, where `n` is the **total** number of characters in `bank`.
['Java', 'Python3']