Easy approach using 2 variables
\nclass Solution {\npublic:\n    int numberOfBeams(vector& bank) {\n        int flag = 1;\n        int ans =0;\n        int count1 =0;\n        int count2 =0;\n
\nclass Solution {\npublic:\n    int numberOfBeams(vector<string>& bank) {\n        int flag = 1;\n        int ans =0;\n        int count1 =0;\n        int count2 =0;\n        for(int i=0;i<bank.size();i++){\n            for(int j=0;j<bank[i].length();j++){\n                if(bank[i][j]==\'1\' && flag ==1){\n                    count1++;\n                }\n                else if(bank[i][j]==\'1\'&& flag ==0){\n                    count2++;\n                }\n            }\n            ans += count1*count2;\n            if(flag == 0 && count2 != 0){\n                count1 = 0;\n                flag = 1;\n            }\n            else if(count1!= 0 && flag ==1) {\n                count2 = 0;\n                flag = 0;\n            }\n           \n        }\n        return ans;\n    }\n};\n
['C++']