bits + binary search || easy to understand || must see
Code\ncpp []\nclass Solution {\npublic:\n    unordered_map<int,set<int>>mp;\n    void preprocess(vector<int>&nums)\n    {\n         //pos --> {}\n         for(i
# Code\n```cpp []\nclass Solution {\npublic:\n    unordered_map<int,set<int>>mp;\n    void preprocess(vector<int>&nums)\n    {\n         //pos --> {}\n         for(int i = 0 ; i < nums.size() ; i++){\n            for(int j = 0 ; j < 32 ; j++){\n                if((nums[i] & (1 << j)) > 0){\n                      //this nums[i] has the jth bit set\n                      mp[j].insert(i);   //jth bit kaun kaun se index m set h\n                }\n            }\n         }\n    }\n    vector<int> smallestSubarrays(vector<int>& nums) {\n         //lower_bound function give the iterator to the first position ele equal or greater than the value\n         //upper_bound function give the iterator to the first position ele greater than the value\n         preprocess(nums);\n\n         vector<int>ans;\n         for(int i = 0 ; i < nums.size() ; i++){\n              int start = i;\n              int end   = i;\n              int curror = 0;\n              curror = curror | nums[i];\n              for(int j = 31 ; j >= 0 ; j--){\n                    \n                   if((curror & (1 << j)) > 0) continue;\n\n                   int pos = fun(j,i);  //get the min / nearest index of such element\n                   if(pos != -1) {\n                         curror = curror | nums[pos];\n                         end = max(end , pos);\n                   } \n              }\n              ans.push_back((end - start + 1));\n         }\n         return ans;\n    }\n    int fun(int pos , int idx){\n        if(mp.find(pos) != mp.end()){   //if we have the pos bit set in any index\n                //finding the index which is just greater then the ith index\n                auto it = mp[pos].upper_bound(idx);\n                if(it == mp[pos].end()) return -1;\n                int ans = *(it);\n                return ans;\n        }\n        return -1;\n    }\n};\n```
['Array', 'Binary Search', 'Bit Manipulation', 'Sliding Window', 'C++']