Sliding Window + Array of Set Bits. Time: O(nlogM), Space: O(logM)
IntuitionThe maximum OR value starting at index, i, will be the subarray going till the end of the array. We will need to use a sliding window with an array of
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The maximum OR value starting at index, i, will be the subarray going till the end of the array. We will need to use a sliding window with an array of set bits to ensure we are not losing any set bits when we reduce the window size by moving right side pointer left.

# Complexity
- Time complexity: $$O(nlogM)$$
- n: length of array
- M: OR value of all elements in the array. With the current approach, we will need to iterate through the bit array thrice for every element. Size of bit array will be log M.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(logM)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
Size of bit array

# Code
```python []
class Solution(object):
    def smallestSubarrays(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        

        max_num = 0

        for num in nums:
            max_num = max_num | num
        
        if max_num == 0:
            return [1]*len(nums)
        #print max_num
        cur = max_num
        
        count = 0
        while cur > 0:
            count += 1
            cur >>= 1
        
        
        bit_arr = [0]*count

        max_so_far = 0
        r = len(nums)-1
        res = [0]*len(nums)

        for i in range(len(nums)-1,-1,-1):
            cur = nums[i]
            idx = 0
            while cur > 0:
                if cur & 1:
                    bit_arr[idx] += 1
                cur >>= 1
                idx += 1
            
            while r > i:
                cur = nums[r]
                idx = 0
                canSkip = True
                while cur > 0:
                    if cur & 1:
                        if bit_arr[idx] <= 1:
                            canSkip = False
                            break
                    cur >>= 1
                    idx += 1
                
                if canSkip:
                    cur = nums[r]
                    idx = 0
                    while cur > 0:
                        if cur & 1:
                            bit_arr[idx] -= 1
                        cur >>= 1
                        idx += 1
                    r -= 1    
                else:
                    break
            
            res[i] = r-i+1
        
        return res
            
            







```
['Python']