✅Easiest solution | PREFIX-SUFFIX | c++
IMPORTANT\nYou can watch the biggest sliding window series on entire internet just using single template by clicking my profile icon and checking my youtube cha
#### IMPORTANT\nYou can watch the biggest sliding window series on entire internet just using single template by clicking my profile icon and checking my youtube channel link from the bio. ( I bet you can solve any sliding window question on leetcode after watching the series do share you thoughts on the same.)\nThankyou and happy leetcoding. \n## **INTUTION:**\n* Just calculate prefix OR (at each index prefix OR will contain OR of all its previous element) and suffix OR ( at each index suffix OR will contain OR of all its next elements.)\n\n* Now if you are lets say standing at current position then you have to find maximum OR value of taking\nOR of each value but after apply operation (multiply by 2 k times) then you have OR value of all elements\njust before of this current index is in prefix array and OR value of all element next to this index in suffix array.\n\n* So just check current number by multiplying by 2k times that whether it is generating maximum answer.\n\n#### **Let\'s take the test case: [12,9] and k=1**\n   Prefix is: 0 12 13 \n   Suffix is: 13 9 0 \n   P= 2  (P=2*K)\n   \n   On calculating --> \n \n**for (int i = 0; i < n; i++) {\n        res = max(res, pre[i] | (nums[i] * p) | suf[i + 1]); \n\t\t// res=max(res,(OR of all numbers before this index) * (current num multiplied with 2k times) * OR of all number after this index) //\n    }**\n\t\n  res= 0 If current num is multiped by 2 k times then answer will be= 25\n  res= 25 If current num is multiped by 2 k times then answer will be= 30\n  \n####  **Let\'s take the test case: [8,1,2] and k=2**\n  Prefix is: 0 8 9 11 \n Suffix is: 11 3 2 0 \n P= 4  (P=2*k)\n \n   On calculating --> \n \n**for (int i = 0; i < n; i++) {\n        res = max(res, pre[i] | (nums[i] * p) | suf[i + 1]);\n    }**\n res= 0 If current num is multiped by 2 k times then answer will be= 35\n res= 35 If current num is multiped by 2 k times then answer will be= 14\n res= 35 If current num is multiped by 2 k times then answer will be= 9\n\nso take maximum res value as answer.\n\n**NOTE\uD83D\uDCDD:**  Some people are confused that whe multiply only current number with 2k times. It may be possible that we can get max answer by spreading multiply of 2 means you can multiply by 2 with multiple numbers why only to just one number.\n \n Dear your doubt is genuine but let you think that when we get maximum OR value\n \n* OR value is directly proportional to the  greater we have a number. \n\n* Now suppose nums=[8,1,2] and k=2 if you think that instead of multiplying by 2k times you can multiply other numbers also means multiply one 2 by 8 another 2 by other number from 1 and 2 but you are wrong here you have to think critically here that I am raising each number to its maximum value by multiplying by 2k times and i am doing it for each number so the number which is generating maximum OR will be our final answer.\n\n* Actually 2k is also a number and we can maximise OR value if this 2k value is making a number maximum in our array.\n\t\n\n```\nlong long maximumOr(vector<int>& nums, int k) {\n    int n = nums.size();\n    vector<long long> pre(n + 1, 0); // Stores prefix bitwise OR values\n    vector<long long> suf(n + 1, 0); // Stores suffix bitwise OR values\n    pre[0] = 0;\n    suf[n] = 0;\n    long long res = 0;\n    long long p = 1; // Used to calculate the power of 2, equivalent to x^k\n    p = p << k; // Left shift k positions to calculate 2^k\n\n    // Calculate prefix bitwise OR values\n    for (int i = 0; i < n; i++) {\n        pre[i + 1] = pre[i] | nums[i];\n    }\n\n    // Calculate suffix bitwise OR values\n    for (int i = n - 1; i >= 0; i--) {\n        suf[i] = suf[i + 1] | nums[i];\n    }\n\n    // Find the maximum result by iterating through the numbers\n    for (int i = 0; i < n; i++) {\n//\tcout<<"res= "<<res<< " If current num is multiped by 2 k times then answer will be= "<<(pre[i] | (nums[i] * p) | suf[i + 1])<<endl; \n        res = max(res, pre[i] | (nums[i] * p) | suf[i + 1]);\n    }\n\n    return res;\n}\n\n```
[]