C++ ||Clean Code|| Easy explanation||Short| T: 90%, Mem:100%
the intution is based on storing prefix sum, but instead of sum, i am storing the number upto that point.\nIt would be easier to understand if we consider decim
the intution is based on storing prefix sum, but instead of sum, i am storing the number upto that point.\nIt would be easier to understand if we consider decimal number system.\nImagine nums represet a decimal number array instead of binary and you have an array like\n1 0 2 3 8 9 0 1\nso at index 0, the number it will form will be simply nums[0] itself.\nbut at index 1, you will first multiply the previous number by 10(base of decimal number system) and then add it to get 10.\nSimilary, at index 2, you will multiply this 10 by 10 and add 2 to get 102.\nat index 3, we multiply 102 by 10 and 3 to get 1023.\nand so on ..\n\nusing this intution, we can easily get the number upto that index in the binary system as well. The only change is instead of multiplying it by base 10, we need to multiply it by 2 (base of binary number system).\n\nNow, this promptly leads to the problem of integer overflow, and that\'s where modulo comes in. Once we start storing the decimal represent of binary numbers at each index, we don\'t really need the whole number, only it\'s modulo-5 as in next step we are simply multiplying it by 2 (not a factor of 5) and only change that occur in it\'s state is due to addition. So we can safely store only moudlo 5 values. This ensures that we only need to store the digits [0,4] and thus avoid the overflow problem\n\n```\nclass Solution {\npublic:\n    vector<bool> prefixesDivBy5(vector<int>& nums) {\n        vector<bool> ans;\n        ans.push_back(nums[0]%5==0);\n        \n        for(int i=1;i<nums.size();i++)\n        {\n            nums[i-1]*=2;//multiplying the starting bits by corresponding base power\n            nums[i]+=nums[i-1];//adding the LSB\n            ans.push_back(nums[i]%5==0); //checking if it\'s divisible by 5\n            nums[i]%=5; //storing only the remainder since rest is not required\n        }\n        return ans;\n    }\n};\n```
['C++']