🔥Java || Prefix - Suffix
Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(N)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long maximumOr(int[] nums, int k) {\n        if(nums.length == 1) {\n            return (long)nums[0] << k;\n        }\n\n        long[] prefix = new long[nums.length];\n        prefix[0] = nums[0];\n\n        for(int i = 1; i < nums.length; i++) {\n            prefix[i] = prefix[i-1] | (long)nums[i];\n        }\n\n        long[] suffix = new long[nums.length];\n        suffix[nums.length - 1] = nums[nums.length - 1];\n\n        for(int i = nums.length - 2; i >= 0; i--) {\n            suffix[i] = suffix[i+1] | (long)nums[i];\n        }\n\n        long ans = Math.max(((long)nums[0] << k) | suffix[1], ((long)nums[nums.length - 1] << k) | prefix[nums.length - 2]);\n\n        for(int i = 1; i < nums.length - 1; i++) {\n            long n = ((long)nums[i] << k) | prefix[i-1] | suffix[i+1];\n            ans = Math.max(ans, n);\n        }\n        return ans;\n    }\n}\n```
['Java']