C++ | 2 approaches |  O(n * 32) | O(n * 32 * logn) | simple implementations
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\nBelow implementation is set + binary search (lower_bound)\n\nTime complexity: **O(n x 32 x logn)**\n\n```\nclass Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n\t\tint n = nums.size();\n\n\t\tvector<set<int>> idx(32);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < 32; j++) {\n\t\t\t\tif ((nums[i] >> j) & 1) {\n\t\t\t\t\tidx[j].insert(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tvector<int> res(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint mn = i;\n\t\t\tfor (int j = 0; j < 32; j++) {\n\t\t\t\tset<int> &st = idx[j];\n\t\t\t\tauto it = st.lower_bound(i);\n\t\t\t\tif (it == st.end()) {\n\t\t\t\t\tst.clear();\n\t\t\t\t} else {\n\t\t\t\t\tmn = max(mn, *it);\n\t\t\t\t}\n\t\t\t}\n\t\t\tres[i] = mn - i + 1;\n\t\t}\n\t\treturn res;\n    }\n};\n\n```\n\nImprovement: \nTime complexity **O(n x 32)**\n\n```\nclass Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n\t\tint n = nums.size();\n\n\t\tvector<queue<int>> idx(32);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < 32; j++) {\n\t\t\t\tif ((nums[i] >> j) & 1) {\n\t\t\t\t\tidx[j].push(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tvector<int> res(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint mn = i;\n\t\t\tfor (int j = 0; j < 32; j++) {\n\t\t\t\tqueue<int> &q = idx[j];\n\t\t\t\twhile (!q.empty() && q.front() < i) q.pop();\n\t\t\t\tif (!q.empty()) {\n\t\t\t\t\tmn = max(mn, q.front());\n\t\t\t\t} \n\t\t\t}\n\t\t\tres[i] = mn - i + 1;\n\t\t}\n\t\treturn res;\n    }\n};\n\n```\n\n\n\n
['C++']