O(32N) C++ solution using hash map
Intuition\nThe intuition in some of these bit related question is that we have a fixed number of bits (30 in this case as max value is 10^9). So storing a hashm
# Intuition\nThe intuition in some of these bit related question is that we have a fixed number of bits (30 in this case as max value is 10^9). So storing a hashmap might be a good idea.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe idea is to first get a vector maxor which stores max possible or for each element. Then we try to reach this max value in a single loop with the help of a hash map. We need the hash map to store the bit values after adding/removing each element. We remove the bits of the element when we remove it and we update our cur or value. \n\n\n# Complexity\n- Time complexity:\nO(32N)\n\n- Space complexity:\nO(N)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n        int n=nums.size();\n        std::vector<int>maxor(n); \n        std::vector<int>resArr(n,-1);   \n        int res; \n        int curor=0;    \n        for(int i=n-1;i>=0;i--)\n        {\n            maxor[i]=curor | nums[i];\n            curor=maxor[i];\n        }\n\n        int l=0;\n        int r=0;\n        std::unordered_map<int,int>map;\n        int cur=0;\n\n        while(resArr[n-1]==-1)\n        {\n            printf("in while; l= %d and r=%d\\n",l,r);\n            if(r<n)\n            {\n                cur |= nums[r];\n                std::bitset<32>bin(nums[r]);\n                for(int j=0;j<32;j++)\n                {\n                    map[j]+=bin[j];\n                }\n            }\n\n            while(l<n && cur==maxor[l])\n            {\n                res=r-l+1;\n                resArr[l]=res<=0?1:res;\n                int toremove=nums[l];\n                std::bitset<32>rem(toremove);\n                for(int j=0;j<32;j++)\n                {\n                    if(map[j]==1 && rem[j]==1)\n                    {\n                        printf("TO BE REMOVED!!!!!!!!!!!  j = %d\\n",j);\n                        cur-=std::pow(2,j);\n                    }\n                    map[j]-=rem[j];\n                }\n                l+=1;\n            }\n            \n            // for(const auto&pairs: map)\n            // {\n            //     std::cout<<pairs.first<<":"<<pairs.second<<" ";\n            // }\n            // std::cout<<std::endl;\n            // printf("curvalue: %d\\n",cur);\n            // printf("resArr:\\n");\n            // for(const auto&elem: resArr)\n            // {\n            //     std::cout<<elem<<" ";\n            // }\n            if(l<n && cur<maxor[l])\n            {\n                r+=1;\n            }\n        }\n        \n\n        for(const auto&elem: maxor)\n        {\n            std::cout<<elem<<" ";\n        }\n        return resArr;\n    }\n};\n```
['C++']