Java, C++, Python | 🚀 A pinch of math in 7 lines explained
\u26A0\uFE0F Disclaimer: The original solution was crafted in Java.\n\nDont forget to upvote if you like the content below. \uD83D\uDE43\n\n# Intuition\nThe tas
> \u26A0\uFE0F **Disclaimer**: The original solution was crafted in Java.\n\nDont forget to upvote if you like the content below. \uD83D\uDE43\n\n# Intuition\nThe task requires us to check whether the binary prefix of each number in an array is divisible by 5. We need to return a boolean array where each index corresponds to the result of the check for the binary prefix ending at the same index in the input array. \n\nThe key insight to solve this problem is to understand that we can keep a running count of the binary number as we iterate through the array and check for divisibility by $$5$$ at each step. As the binary number can be very large, we can take advantage of the fact that $$(a*b) \\mod n==((a \\bmod n)*(b \\mod n)) \\mod n$$.\n\n# Approach\nWe initialize a counter to keep track of the running binary number and an array list to store the results. For each number in the input array, we shift the current counter value to the left by one bit (equivalent to multiplying by $$2$$) and add the current number. We then take the modulus by $$5$$ and check if the result is $$0$$. If it is, we add `true` to the results array; otherwise, we add `false`.\n\n# Complexity Analysis\n- Time complexity: The time complexity is $$O(n)$$, where $$n$$ is the length of the input array, because we make a single pass through the array.\n- Space complexity: The space complexity is $$O(n)$$, where $$n$$ is the length of the input array, because we store a result for each element in the array.\n\n# Code\n```java []\nclass Solution {\n    public List<Boolean> prefixesDivBy5(int[] nums) {\n        var result = new ArrayList<Boolean>(nums.length);\n        long counter = 0;\n        for (int num : nums) {\n            counter = ((counter << 1) + num) % 5;\n            result.add(counter == 0);\n        }\n        return result;\n    }\n}\n```\n``` cpp []\nclass Solution {\npublic:\n    vector<bool> prefixesDivBy5(vector<int>& nums) {\n        vector<bool> result;\n        int counter = 0;\n        for (int num : nums) {\n            counter = ((counter << 1) + num) % 5;\n            result.push_back(counter == 0);\n        }\n        return result;\n    }\n};\n\n```\n``` python3 []\nclass Solution:\n    def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n        result = []\n        counter = 0\n        for num in nums:\n            counter = ((counter << 1) + num) % 5\n            result.append(counter == 0)\n        return result\n\n```
['C++', 'Java', 'Python3']