C++ | Using Precomputation
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
# 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    \n    // check current element is creating maximum OR or not\n    long long checkForCurrent(long long curr , int k){\n        \n        while(k--) curr *= 2;\n        \n        return curr;\n    }\n    \n    long long maximumOr(vector<int>& nums, int k) {\n        \n        // input array length\n        int n = nums.size();\n        \n        // result & current OR\n        long long max_Or = 0 , curr = 0;\n        \n        // create prefix OR\n        vector<int>pre(n);\n        pre[0] = nums[0];\n        \n        for(int i=1;i<n;i++) pre[i] = pre[i-1] | nums[i];\n        \n        \n        // create suffix OR\n        vector<int>suf(n);\n        suf[n-1] = nums[n-1];\n        \n        for(int i=n-2;i>=0;i--) suf[i] = suf[i+1] | nums[i];\n\n        \n        // if array contains only 1 element\n        if(n == 1) return checkForCurrent(nums[0],k);\n        \n        // check for first element\n        curr = checkForCurrent(nums[0],k) | suf[1];  \n        max_Or = max(curr,max_Or);\n            \n\n        // check for last element\n        curr = checkForCurrent(nums[n-1],k) | pre[n-2];  \n        max_Or = max(curr,max_Or);\n        \n        // check for remaining element\n        for(int i=1;i<n-1;i++){\n            \n            curr = checkForCurrent(nums[i],k);\n            \n            curr = suf[i+1] | pre[i-1] | curr;\n            max_Or = max(curr,max_Or);\n            \n        }\n        \n        // result maximum OR\n        return max_Or;\n        \n    }\n};\n```
['Array', 'Bit Manipulation', 'Suffix Array', 'Prefix Sum', 'C++']