O(n) Solution | Prefix and Suffix Array
Intuition and Approach\n Describe your approach to solving the problem. \nThe problem ask us to remove atmost one element and calculate the maximum score.\n\n# 
# Intuition and Approach\n<!-- Describe your approach to solving the problem. -->\nThe problem ask us to remove atmost one element and calculate the maximum score.\n\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```cpp []\nclass Solution {\npublic:\n    long long gcd(long long a, long long b){\n        if(a==0 ) return b;\n        if(b==0) return a;\n        return gcd(b, a%b);\n    }\n    long long maxScore(vector<int>& nums) {\n        int n=nums.size();\n        vector<long long> gcdleft(n+2,0);\n        vector<long long> gcdright(n+2,0);\n        vector<long long> lcmleft(n+2,1);\n        vector<long long> lcmright(n+2,1);\n        for(int i=1;i<=n;i++){\n            gcdleft[i]=gcd(gcdleft[i-1],nums[i-1]);\n            lcmleft[i]= (lcmleft[i-1]*nums[i-1])/gcd(lcmleft[i-1],nums[i-1]);\n        }\n        for(int i=n;i>0;i--){\n            gcdright[i]=gcd(gcdright[i+1],nums[i-1]);\n            lcmright[i]= (lcmright[i+1]*nums[i-1])/gcd(lcmright[i+1],nums[i-1]);\n        }\n        long long ans= gcdleft[n]*lcmleft[n];\n        long long ans1= gcdright[1]*lcmright[1];\n        assert(ans==ans1);\n        for(int i=1;i<=n;i++){\n            long long tempgcd  = gcd(lcmleft[i-1],lcmright[i+1]);\n            ans=max(ans, ((lcmleft[i-1]/tempgcd)*(lcmright[i+1]) * gcd(gcdleft[i-1], gcdright[i+1])));\n        }\n        return ans;\n    }\n};\n```
['C++']