EASY|| FULLY EXPLAINED ||STEP WISE|| JAI SHREE RAM.
Intuition\n Describe your first thoughts on how to solve this problem. \n- Imagine laser beams connecting security devices on different rows like a grid.\n- Foc
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Imagine laser beams connecting security devices on different rows like a grid.\n- Focus on rows with devices, as empty rows don\'t create beams.\n- Count beams by pairing devices from one row with devices on the next non-empty row.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count Devices in Each Row:\nCreate an array NoOfDevicesinRow to store device counts for each row.\n2. Iterate and Calculate Beams:\nInitialize pointers i and j to point to the first two rows.\n3. Iterate while j is within bounds:\nSkip empty rows by incrementing j until a row with devices is found.\n4. Calculate beams between rows i and j: ans += NoOfDevicesinRow[i] * NoOfDevicesinRow[j].\nUpdate i to j for the next iteration.\nMove j to the next row.\n5. Return Total Beams:\nReturn the calculated ans value, representing the total number of laser beams.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(m * n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nPLEASE UPVOTE AND LETS CONNECT ON LINKEDIN , VISIT PROFILE FOR LINK.\n# Code\n```\nclass Solution {\n    public int numberOfBeams(String[] bank) {\n        // Count devices in each row\n        int[] devicesPerRow = new int[bank.length];\n        for (int i = 0; i < bank.length; i++) {\n            int deviceCount = 0;\n            for (char c : bank[i].toCharArray()) {\n                if (c == \'1\') {\n                    deviceCount++;\n                }\n            }\n            devicesPerRow[i] = deviceCount;\n        }\n\n        // Calculate total beams\n        int totalBeams = 0;\n        int i = 0; // Pointer for the first row\n        int j = 1; // Pointer for the next row\n        while (j < bank.length) {\n            // Skip empty rows\n            while (j < bank.length - 1 && devicesPerRow[j] == 0) {\n                j++;\n            }\n\n            // Calculate beams between rows i and j\n            totalBeams += devicesPerRow[i] * devicesPerRow[j];\n\n            // Update pointers for the next iteration\n            i = j;\n            j++;\n        }\n\n        return totalBeams;\n    }\n}\n\n```
['Array', 'Java']