Python || Bitmasking || O(31*n)
Keep track of all bits which have been set by latest index from right.Your answer is maximum of those.If that bit is never set anytime, don\'t consider that ind
Keep track of all bits which have been set by latest index from right.Your answer is maximum of those.If that bit is never set anytime, don\'t consider that index for answer.\n```\nclass Solution:\n    def smallestSubarrays(self, nums: List[int]) -> List[int]:\n        n=len(nums)\n        ans=[1]*n\n        arr=[-1]*31\n        for i in range(n-1,-1,-1):\n            mmax=-1\n            for idx in range(31):\n                if (nums[i] & (1<<idx))!=0:\n                    arr[idx]=i\n                mmax=max(mmax,arr[idx])\n            if mmax!=-1:\n                ans[i]=mmax-i+1\n        return ans\n```\n
[]