O(1) space and O(row*column) time complexity C++ easy solution
Intuition\nWe keep on calculating the no. of security devices in a single row\nAfter having calculated the no. of devices in a single row , we will calculate th
# Intuition\nWe keep on calculating the no. of security devices in a single row\nAfter having calculated the no. of devices in a single row , we will calculate the no. of devices in the next row.\nnow the total number of laser beams between the two rows will be equal to no of.\n(previous *current) row machines ----(a simple intuition).\n\nBut lets also keep a simple edge case under consideration when the number of deviced in a row will be equal to 0...then we will ignore that row.\n\n# Approach\nStep1) We will start from index 0 assuming previous and current row machines to be 0 initially.\n\nStep2) Now we will iterate through the current row and calculate the total no. of machines in that row by incrementing the variable \'curr\' each time we encounter an \'1\' in the string.\n\nStep3) Now we will calculate the no. of beams between the previous and current row and increment the value of ans by that value .\nie:- ans+=prev*curr.\n\nStep4) In the next loop if the \'curr\' is not 0 (ie:-some machines have been found previously), then we simply make prev value equal to curr and curr as 0(for current row).\nElse ignore the previous row by keeping the prev as same as before.\n\nRepeat the loop till we reach the last string and calculate the total number of beams.\n\n\n\n\n# Complexity\n- Time complexity:\nO(row*column)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfBeams(vector<string>& bank) {\n        int prev=0;\n        int curr=0;\n        int ans=0;\n        for ( auto it:bank){\n             if(curr!=0){prev=curr;}\n            curr=0;\n            string s=it;\n            for (auto itt:it){\n                if(itt==\'1\') curr++;\n            }\n            ans+=curr*prev;\n        }\n        return ans;\n    }\n};\n```
['C++']