Easy to Understand Solution | Prefix | Suffix
\n#define ll long long\nclass Solution {\npublic:\n    ll mypow(ll a, ll b) {\nll res = 1;\nwhile (b > 0) {\nif (b & 1)\nres = res * a*1ll;\na = a * a*1ll;\nb >
```\n#define ll long long\nclass Solution {\npublic:\n    ll mypow(ll a, ll b) {\nll res = 1;\nwhile (b > 0) {\nif (b & 1)\nres = res * a*1ll;\na = a * a*1ll;\nb >>= 1;\n}\nreturn res;\n}\n    long long maximumOr(vector<int>& nums, int k) {\n        int n=nums.size();\n        ll x=0;\n        if(n==1) return 1ll*nums[0]*mypow(2,k);\n        vector<ll> pre(n,0),suf(n,0);\n        for(int i=0;i<n;i++)\n        {\n           \n            if(i==0)\n                pre[i]=nums[i];\n            else\n            pre[i]=pre[i-1]|nums[i];\n        }\n        for(int i=n-1;i>=0;i--)\n        {\n            if(i==n-1)\n                suf[i]=nums[i];\n            else\n                suf[i]=suf[i+1]|nums[i];\n        }\n        ll ans=0;\n       for(int i=0;i<n;i++)\n       {\n           ll x=1ll*nums[i]*1ll*mypow(2,k);\n           if(i==0)\n           {\n               ans=max(ans,x|suf[i+1]);\n           }\n           else if(i==n-1)\n           {\n               ans=max(ans,x|pre[i-1]);\n           }\n           else\n           {\n               ans=max(ans,x|pre[i-1]|suf[i+1]);\n           }\n       }\n       return ans; \n     \n    }\n};\n```
[]