Using Prefix Method | C++ Easy Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nWe know that there should be only one number that should be multipled by 2^k as every t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe know that there should be only one number that should be multipled by 2^k as every time we multiply a number by 2 there will be shift in a bit of that number, so that number became larger and larger.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe use prefix  and postfix arrays to store **OR** of numbers before and after for a number\n# 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 {\npublic:\n    long long maximumOr(vector<int>& nums, int k) {\n        int n = nums.size(); \n        vector<int> pre(n, 0), post(n, 0); \n        \n        for(int i=1; i<n; i++) pre[i] = (pre[i-1] | nums[i-1]); \n        for(int i = n-2; i>=0; i--) post[i] = (post[i+1] | nums[i+1]); \n        \n        long long res = 0; \n        \n        for(int i=0; i<n; i++){\n            long long num = nums[i]; \n            num *= pow(2, k); \n            res = max(res, pre[i]|num|post[i]);\n        }\n        return res;\n    }\n};\n```
['Dynamic Programming', 'Prefix Sum', 'C++']