Prefix and Suffix OR
Code\n\ntypedef long long ll;\nclass Solution {\npublic:\n    long long maximumOr(vector<int>& nums, int k) {\n        ll val = 1, n = size(nums);\n        for(
# Code\n```\ntypedef long long ll;\nclass Solution {\npublic:\n    long long maximumOr(vector<int>& nums, int k) {\n        ll val = 1, n = size(nums);\n        for(int i=1; i<=k; ++i) val *= 2;\n        vector<ll> pre(n),suff(n);\n        pre[0] = nums[0];\n        suff[n-1] = nums[n-1];\n        for(int i=1; i<n; ++i) pre[i] = pre[i-1] | nums[i];\n        for(int i=n-2; i>=0; --i) suff[i] = suff[i+1] | nums[i];\n        ll ans = 0;\n        for(int i=0; i<n; ++i){\n            ll x = 0;\n            if(i>0) x=pre[i-1];\n            if(i != n-1) x |= suff[i+1];\n            x |= (nums[i]*1ll*val);\n            ans = max(ans,x);\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'Suffix Array', 'Prefix Sum', 'Bitmask', 'C++']