[C++ / Cpp] | Bit Solution | Explaination | O(30)
\n\t\t// jai shri ram\n\t\t//we are using the or property if the ith idx is one then it will not change further.\n\t\t// we are checking the min idx from cur id
```\n\t\t// jai shri ram\n\t\t//we are using the or property if the ith idx is one then it will not change further.\n\t\t// we are checking the min idx from cur idx that is responsible for set the ith bit and updating it from right to left  \n\t\tvector<int>mp(31,-1);\n        vector<int>ans;\n        int n=nums.size();\n        for(int i=n-1;i>=0;i--){\n            for(int j=0;j<=30;j++){\n                int mask=(1<<j); \n                if((mask & nums[i])){ //checking the jth bit is set or not\n                    mp[j]=i; // if the bit is set then update the jth bit to cur idx means this jth bit can be set by this idx;\n                }\n            }\n            int res=-1;\n            for(auto x:mp){\n                res=max(res,x); // finding the max idx which are contributing to max or\n            }\n            if(res!=-1) ans.push_back(res-i+1);\n            else if(res==-1 && nums[i]==0) ans.push_back(1); // if there are zeroes to the right side then no bit is set then the ans will be 1.\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n```
['Bit Manipulation', 'C', 'C++']