Simple Java | (with meme)
\n# Code\n\nclass Solution {\n    public long maximumOr(int[] nums, int k) {\n        //Arrays.sort(nums);\n        if(nums.length==1)\n            return nums[
\n# Code\n```\nclass Solution {\n    public long maximumOr(int[] nums, int k) {\n        //Arrays.sort(nums);\n        if(nums.length==1)\n            return nums[0]*(int)Math.pow(2,k);\n\n        long[] prev = new long[nums.length];\n        long[] post = new long[nums.length];\n        long res = Integer.MIN_VALUE;\n\n        prev[0] = 0;\n        prev[1] = nums[0];\n\n        post[nums.length-1] = 0;\n        post[nums.length-2] = nums[nums.length-1];\n\n        for(int i=2;i<nums.length;i++){\n            prev[i] = nums[i-1]|prev[i-1];\n        } \n        for(int i=nums.length-3;i>=0;i--){\n            post[i] = nums[i+1]|post[i+1];\n        }     \n\n        for(int i=nums.length-1;i>=0;i--){\n            long exc = prev[i] | post[i];\n            long self = (long)nums[i]<<k;\n            res = Math.max(res,exc | self);\n        }\n            \n        return res;\n    }\n\n}\n```\n\n![image.png](https://assets.leetcode.com/users/images/404b1a2c-55a4-4bae-b23f-dcd7e4b4ae4c_1723716074.6420434.png)\n
['Java']