Count , Multiply and Add
Intuition\n Describe your first thoughts on how to solve this problem. \n\nA laser beam is formed by connecting one safety device to the another safety device w
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nA laser beam is formed by connecting one safety device to the another safety device which is just below it . Hence we need to find out the number of devices in each row and multiply it by number of devices in the next row . If next row has zero devices than skip that row and check for next to next row\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nWe have a getOnes function which simply returns the count of ones i.e safety devices in the row \n\n\nwe have a variable prev which keeps count of devices in the last row ( last row which has non-zero devices)\n\n\nthis variable will only be changed when we get a row with non zero devices.\n\nwe will multiply current row devices count and  prev row device count and then update the current to prev\n\n# Complexity\n- Time complexity:O(N*M)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int getOnes( string str)\n    {\n        int ones = 0;\n\n        for( auto ele : str)\n        {\n            if( ele == \'1\') ones += 1;\n        }\n\n        return ones;\n    }\n    int numberOfBeams(vector<string>& bank) {\n        \n        int prev = 0;\n        int ans = 0;\n\n        for( int i = 0; i < bank.size() ; i++ )\n        {\n            int current = getOnes(bank[i]); \n\n            if(current != 0)\n            {\n                ans += current * prev;\n                prev = current;\n            }\n            \n        }\n        return ans;\n    }\n\n};\n```
['C++']