Easiest and most efficient solution using bit manipulation
Intuition Assume the array has only 0 and 1.\nThen the question changes:\nIf A[i] = 1, shortest array is [A[i]], length is 1.\nIf A[i] = 0, we need to find the 
# Intuition Assume the array has only 0 and 1.\nThen the question changes:\nIf A[i] = 1, shortest array is [A[i]], length is 1.\nIf A[i] = 0, we need to find the index j of next 1,\nthen j - i + 1 is the length of shortest subarray.\nIf no next 1, 1 is the length\n\nTo solve this problem,\nwe can iterate the array reversely\nand keep the index j of last time we saw 1.\nres[i] = max(1, last - i + 1)\n\n# Complexity\n- Time complexity:O(n*30)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n        vector<int> smallestSubarrays(vector<int>& nums) {\n        int n=nums.size();\n        vector<int> ans(n,1);\n        vector<int> next_one(30);\n        for(int i=n-1;i>=0;i--) {\n            for(int j=0;j<30;j++) {\n                if((nums[i] & (1<<j))) next_one[j]=i;\n                ans[i]=max(ans[i],next_one[j]-i+1);\n            }\n        }\n        return ans;\n    }\n};\n```
['Bit Manipulation', 'C++']