C++ || Prefix & Suffix || Beats 100% || Easy to Understand
Complexity
Time complexity: O(n⋅log(max_value)) (max_value here 30)

Space complexity: O(n)
Code
# Complexity\n- Time complexity: O(n\u22C5log(max_value)) (max_value here 30)\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 []\n#define ll long long\nclass Solution {\npublic:\n    long long gcd(ll div, ll qo)\n    {\n        while(qo != 0)\n        {\n            ll rem = div % qo;\n            div = qo;\n            qo = rem;\n        }\n        return div;\n    }\n\n    long long lcm(ll a, ll b) {\n        return (a / gcd(a, b)) * b;\n    }\n\n    long long maxScore(vector<int>& v) {\n        if(v.empty()) return 0;\n        int n = v.size();\n        if(n==1) return v[0]*v[0];\n\n        vector<ll> preGCD(n,v[0]), preLCM(n,v[0]), sufGCD(n,v[n-1]), sufLCM(n,v[n-1]);\n\n        for(int i=1; i<n; i++)\n        {\n            preGCD[i] = gcd(preGCD[i-1],v[i]);\n            preLCM[i] = lcm(preLCM[i-1],v[i]);\n        }\n\n        for(int i=n-2; i>=0; i--)\n        {\n            sufGCD[i] = gcd(sufGCD[i+1],v[i]);\n            sufLCM[i] = lcm(sufLCM[i+1],v[i]);\n        }\n\n        long long ans = preGCD[n-1] * preLCM[n-1];\n        ans = max({ans,preGCD[n-2] * preLCM[n-2], sufGCD[1] * sufLCM[1]});\n\n        for(int i=1; i<n-1; i++)\n        {\n            ll a = lcm(preLCM[i-1],sufLCM[i+1]);\n            ll b = gcd(preGCD[i-1],sufGCD[i+1]);\n\n            ans = max(ans, a*b);\n        }\n\n        return ans;\n\n    }\n};\n```
['C++']