🤯 100% TC 100% SC | Bit Manipuation | Explained | Python | Super fast
\n\nLogic: When we do an OR operation, once a bit becomes 1, it stays 1 afterwards no matter how many OR operations you do. So when we iterate from left to righ
![image](https://assets.leetcode.com/users/images/6dc31098-5267-472f-b795-ebbef278e52e_1663437342.138748.png)\n\nLogic: When we do an OR operation, once a bit becomes 1, it stays 1 afterwards no matter how many OR operations you do. So when we iterate from left to right, as soon as a bit becomes 1, that is the best index (least possible) we will need to travel to make that bit 1. \n\n**We need to start from the end and update the least index required for making each bit 1. Once we update, the max index needed to make any bit 1 is the answer for the current index.**\n\nEg: [1, **3**] -> bitform =  [01, **11**]\n**We iterate from right to left**\ncurrIndex = 1\nmax index to make LSB (rightmost bit) 1 = 1\nmax index to make MSB (leftmost bit) 1 = 1\nbestBitIndex = [1, 1]\n\n[**1**, 3] -> bitform =  [**01**, 11]\ncurrIndex = 0\nmax index to make LSB (rightmost bit) 1 = 0 (we dont need to go till index 1 now, this bit will stay 1 starting from index 0)\nmax index to make MSB (leftmost bit) 1 = 1 (in order to make this bit 1, we still have to travel till index 1)\nbestBitIndex = [1, 0]\n\nUpvote if you understood the logic :) \n\n```\nclass Solution:\n    def smallestSubarrays(self, nums: List[int]) -> List[int]:\n        ans = [None] * len(nums)\n        n = len(nums)\n        bestBitIndices = [0] * 32\n\n        for numIndex in range(len(nums) - 1, -1, -1):\n            \n            for bitIndex in range(32):\n                if nums[numIndex] & (1 << bitIndex):\n\t\t\t\t    # if 0 we need to atleast travel till the current index\n                    if bestBitIndices[bitIndex] == 0:\n                        bestBitIndices[bitIndex] = numIndex\n                    else:\n                        bestBitIndices[bitIndex] = min(bestBitIndices[bitIndex], numIndex)\n                    \n            ans[numIndex] = max(1, max(bestBitIndices) - numIndex + 1)\n        \n        return ans\n```
['Python']