solved by two pointers
\nclass Solution {\n    public int[] smallestSubarrays(int[] nums) {\n        int n = nums.length;\n        int[] max = new int[n];\n        int now = 0;\n\t\t/
```\nclass Solution {\n    public int[] smallestSubarrays(int[] nums) {\n        int n = nums.length;\n        int[] max = new int[n];\n        int now = 0;\n\t\t//1. The maximum value is calculated first (going back from N-1)\n        for(int i = n-1; i >= 0; i--){\n            now |= nums[i];\n            max[i] = now;\n        }\n        int[] bit = new int[31];\n        int right = 0;\n        now = 0;\n        int[] cnt = new int[n];\n        for(int i = 0; i < n; i++){\n\t\t    //2. Keep adding until the maximum value is reached.\n            while(right < n && now < max[i]){\n                for(int j = 0; j < 31; j++){\n                    if((nums[right] >> j) % 2 == 1){\n                        bit[j]++;\n\t\t\t\t\t\t//3. OR value increases when that bit goes 0 => 1\n                        if(bit[j] == 1){\n                            now += (1 << j);\n                        }\n                    }\n                }\n                right++;\n            }\n            cnt[i] = Math.max(1,right-i);\n\t\t\t// 4. Remove nums[i] from the OR value\n            for(int j = 0; j < 31; j++){\n                if((nums[i] >> j) % 2 == 1){\n                    bit[j]--;\n                    if(bit[j] == 0){\n\t\t\t\t\t    // 5. OR value decreases when the bit becomes 1 => 0\n                        now -= (1 << j);\n                    }\n                }\n            }\n        }\n        return cnt;\n    }\n}\n```
['Two Pointers', 'Java']