Prefix and suffix arrays
Intuition\n1. Make a Prefix OR & Suffix OR array.\n2. Now try to traverse the array and maximise the \nprefix[i-1] | nums[i]*2^k | suffix[i+1],\n\nthat means fo
# Intuition\n1. Make a Prefix OR & Suffix OR array.\n2. Now try to traverse the array and maximise the \n```prefix[i-1] | nums[i]*2^k | suffix[i+1]```,\n\nthat means for each ```nums[i]``` we\'re multiplying it with `2^k` ORing it with `prefix[i-1]` and `suffix[i+1]`, and checking if this `nums[i]` is giving us the Maximum Or.\n\n**Solve the 2nd example for better intution.**\n\n\n# Code\n```\nclass Solution {\n    public long maximumOr(int[] nums, int k) {\n        int n = nums.length;\n        \n        long[] pref = new long[n], suff = new long[n];\n        pref[0] = nums[0]; suff[n-1] = nums[n-1];\n\n        for(int i=1; i<n; i++){\n            pref[i] = (pref[i-1] | nums[i]);\n        }\n        \n        for(int i=n-2; i>=0; i--){\n            suff[i] = (suff[i+1] | nums[i]);\n        }\n        \n        long res = 0, mult = 1 << k;\n        //mult = 2^k\n        \n        for(int i=0; i<n; i++){\n            //temp = nums[i]*2^k\n\n            long temp = (long) mult * nums[i];\n\n            if(i-1 >= 0){\n                //temp = temp | pref[i-1];\n                temp |= pref[i-1];\n            }\n            \n            if(i+1 < n){\n                //temp = temp | suff[i+1];\n                temp |= suff[i+1];\n            }\n            \n            res = Math.max(temp, res);\n        }\n                \n        return res;\n    }\n}\n```
['Java']