C++ Interative Solution
Intuition\nFind no of security devices in a row for each row. The idea is to find lasers between rows. Lasers may form between security devices in different row
# Intuition\nFind no of security devices in a row for each row. The idea is to find lasers between rows. Lasers may form between security devices in different row, passing through rows with 0 security devices. \n\nTherefore, find number of security devices in each row, we may skip rows having no security devices as laser will pass through it and empty layer isn\'t important from calculation point of view. \n\nNumber of lasers between two non-empty layers is simply the **product of security devices in current row and security devices in previous row**.\n\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfBeams(vector<string>& bank) {\n        vector<int>beams;\n        for(auto i:bank){\n            int sum=0;\n            for(auto j:i)\n                sum+=j-\'0\';\n            if(sum)\n                beams.push_back(sum);\n        }    \n        int n=beams.size();\n        if(n<2) \n            return 0;\n        int prev=beams[0];\n        int ans=0;\n        for(int i=1;i<n;i++){\n            ans+=prev*beams[i];\n            prev=beams[i];\n        }\n        return ans;\n    }\n};\n```
['Array', 'C++']