Laser Counter | Java | C++
Intuition\nNumber of lasers between two security devices rows having \'secCnt1\' and \'secCnt2\' number of security devices is equal to secCnt1 * secCnt2.\n\n# 
# Intuition\nNumber of lasers between two security devices rows having \'secCnt1\' and \'secCnt2\' number of security devices is equal to secCnt1 * secCnt2.\n\n# Approach\nCover the bank floor row by row.\n\nIf there are security devices in the current row then the amount of lasers than can be added by these devices to the total laser count is curSecDevCnt * prevSecDevCnt. \n\nUpdate prevSecDevCnt if current row have security devices.\n\n# Complexity\n- Time complexity:\nO(rows * cols), rows is number of rows in bank floor and cols is number of columns in bank floor.\n\n- Space complexity:\nO(1)\n# Code\nC++\n```\nclass Solution {\npublic:\n    int numberOfBeams(vector<string>& bank) {\n        int prevSecDevCnt = 0, rows = bank.size(), cols = bank[0].size(), laserCnt = 0;\n        for(int r = 0; r < rows; r++){\n            int curSecDevCnt = 0;\n            for(int c = 0; c < cols; c++){\n                curSecDevCnt += bank[r][c] - \'0\';   \n            }\n            laserCnt  += curSecDevCnt * prevSecDevCnt;\n            if(curSecDevCnt > 0)\n                prevSecDevCnt = curSecDevCnt;\n        }\n        return laserCnt;\n    }\n};\n```\nJava\n```\nclass Solution {\n    public int numberOfBeams(String[] bank) {\n        int prevSecDevCnt = 0, rows = bank.length, cols = bank[0].length(), laserCnt = 0;\n        for(int r = 0; r < rows; r++){\n            int curSecDevCnt = 0;\n            for(int c = 0; c < cols; c++){\n                curSecDevCnt += bank[r].charAt(c) - \'0\';   \n            }\n            laserCnt  += curSecDevCnt * prevSecDevCnt;\n            if(curSecDevCnt > 0)\n                prevSecDevCnt = curSecDevCnt;\n        }\n        return laserCnt;\n    }\n}\n```
['C++', 'Java']