PrefixSum + Binary Search | Java
\nclass Solution {\n    public int[] smallestSubarrays(int[] nums) {\n        int n = nums.length;\n        int[][] prefix = new int[n+1][32];\n        for(int 
```\nclass Solution {\n    public int[] smallestSubarrays(int[] nums) {\n        int n = nums.length;\n        int[][] prefix = new int[n+1][32];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<32;j++){\n                prefix[i+1][j] =  prefix[i][j];\n                if(((1<<j)&nums[i])!=0) prefix[i+1][j]++;\n            }\n        }\n        int[] ans = new int[n];\n        for(int i=0;i<n;i++){\n            int l = i+1,r = n;\n            while(l<r){\n                int mid = (l+r)/2;\n                boolean f =  true;\n                for(int j=0;j<32;j++){\n                    if((prefix[r][j]-prefix[i][j])!=0&&(prefix[mid][j]-prefix[i][j])==0)  {\n                        f = false;\n                        break;\n                    }\n                }\n                if(f)  r = mid;\n                else  l = mid+1;\n            }\n            ans[i] = r - i;\n        }\n        return ans;\n    }\n}\n```
[]