C++ | Suffix array for bits for storing Bits position | Accepted
class Solution {\npublic:\n    vector smallestSubarrays(vector& nums) {\n        \n        \n        vector temp = nums;\n        int n=nums.size();\n        \n
class Solution {\npublic:\n    vector<int> smallestSubarrays(vector<int>& nums) {\n        \n        \n        vector<int> temp = nums;\n        int n=nums.size();\n        \n        \n        vector<int> ans(n,-1);\n        vector<vector<int>> bits(32,vector<int>(n,n));\n        \n        \n        for(int i=0;i<32;i++)\n        {\n            \n            for(int j=n-1;j>=0;j--){\n                \n                if(((nums[j] >> i)&1) == 1){\n                    bits[i][j] = j;\n                }else{\n                    if(j!=(n-1))bits[i][j] = bits[i][j+1];\n                }\n            }\n            \n        }\n        \n        \n        for(int j=0;j<n-1;j++)\n        {\n            int len=INT_MIN;\n            for(int i=0;i<32;i++)\n            {\n                if(bits[i][j+1]!=n){\n                    len=max(len,bits[i][j]);\n                }\n            }\n            \n            if(len!=INT_MIN){\n                ans[j]=len-j+1;\n            }else{\n                ans[j]=1;\n            }\n        }\n        ans[n-1]=1;\n        \n        \n        return ans;\n        \n    }\n};
['Suffix Array']