🔥VERY SIMPLE LOGIC using only vector🔥🔥. Beginner friendly and easy to understand.
\n\n# Approach\nFind the closest distance of the bit we are checking if it is set in subsequent positions using lower bound.\nWe take the max of all such distan
\n\n# Approach\nFind the closest distance of the bit we are checking if it is set in subsequent positions using lower bound.\nWe take the max of all such distances for that index in nums.\n\n# Complexity\n- Time complexity:\n $$O(n*32*logn)$$ \n\n- Space complexity:\n $$O(n*32)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n        vector<vector<int>>v(32);\n        int n=nums.size();\n        for(int i=0;i<32;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(nums[j]&(1ll<<i))v[i].push_back(j);\n            }\n        }\n        vector<int>ans;\n         for(int i=0;i<n;i++)\n        {\n            int mn=1;\n            for(int j=0;j<32;j++)\n            {\n                if(!v[j].size())continue;\n                int in=lower_bound(v[j].begin(),v[j].end(),i)-v[j].begin();\n                if(in==v[j].size())continue;\n                mn=max(mn,v[j][in]-i+1);\n            }\n            ans.push_back(mn);\n        }\n        return ans;\n    }\n};\n```
['C++']