Sliding Window on Bits | C++
The key idea is to start fom the end and keep removing the element which do not alter the value of the maximum bitwise OR.\n\n\nclass Solution {\npublic:\n    \
The key idea is to start fom the end and keep removing the element which do not alter the value of the maximum bitwise OR.\n\n```\nclass Solution {\npublic:\n    \n    bool isOk(vector<int> &crt, vector<int> &last){\n        vector<int> temp(crt);\n        for(int i = 0; i<64; i++){\n            temp[i] = temp[i] - last[i];\n        }\n        for(int i = 0; i<64; i++){\n            if(!temp[i]&&crt[i])return false;\n        }\n        return true;\n    }\n    \n    vector<int> smallestSubarrays(vector<int>& nums) {\n        vector<int> ans(nums.size());\n        vector<vector<int>> bits(nums.size(), vector<int>(64, 0));\n        for(int i = 0; i<nums.size(); i++){\n            int temp = nums[i];\n            int k = 0;\n            while(temp){\n                bits[i][k++] = temp%2;\n                temp = temp/2;\n            }\n        }\n        ans[nums.size()-1] = 1;\n        vector<int> crt = bits[nums.size()-1];\n        int last = nums.size()-1;\n        for(int i = nums.size()-2; i>=0; i--){\n            for(int j = 0; j<64; j++){\n                crt[j] += bits[i][j];\n            }\n            while(last>i&&isOk(crt, bits[last])){\n                for(int k = 0; k<64; k++){\n                    crt[k] = crt[k] - bits[last][k];\n                }\n                last--;\n            }\n            ans[i] = last-i+1;\n        }\n        return ans;\n    }\n};\n```
[]