Sliding Window Intuitive
First find the maximum OR of the array arr and then search for the maximum or from the start. Once the maximum OR is found update the maximum OR if required and
First find the maximum OR of the array arr and then search for the maximum or from the start. Once the maximum OR is found update the maximum OR if required and remove the leftmost element of the array from the current OR.\n```\nclass Solution {\n    public int[] smallestSubarrays(int[] nums) {\n        int[] res=new int[nums.length];\n        int freq[]=new int[32];\n        int or=0;\n        for(int i:nums){\n            or|=i;\n            addFreq(i,freq);\n        }\n        int l=0;\n        int r=0;\n        int cur=0;\n        int cFreq[]=new int[32];\n        while(r<nums.length){\n            if(or==0){\n                res[l]=1;\n                l++;\n                r++;\n                continue;\n            }\n            cur|=nums[r];\n            addFreq(nums[r],cFreq);\n            while(l<nums.length&&cur==or&&cur!=0){\n                res[l]=r-l+1;\n                dFreq(nums[l],freq);\n                or=update(freq);\n                dFreq(nums[l],cFreq);\n                cur=update(cFreq);\n                l++;\n            }\n            \n            r++;\n        }\n        res[nums.length-1]=1;\n        return res;\n    }\n    \n    public void addFreq(int i,int[] freq){\n        int j=0;\n        while(i>0){\n            int bit=i&1;\n            i=i>>1;\n            if(bit==1) freq[j]++;\n            j++;\n        }\n        \n    }\n    \n    public void dFreq(int i,int[] freq){\n        int j=0;\n        while(i>0){\n            int bit=i&1;\n            i=i>>1;\n            if(bit==1) freq[j]--;\n            j++;\n        }\n    }\n    \n    public int update(int[] freq){\n        int ans=0;\n        for(int i=0;i<32;i++){\n            if(freq[i]>0)\n            ans|=(1<<i);\n        }\n        return ans;\n    }\n    \n    \n}\n````
['Two Pointers', 'Sliding Window', 'Java']