C++ solution prefix + suffix array
\n// Please, upvote if you like it. Thanks :-)\nlong long maxScore(vector<int>& nums) {\n\tint n = nums.size();\n\tif (n == 1)\n\t\treturn nums.back() * nums.ba
```\n// Please, upvote if you like it. Thanks :-)\nlong long maxScore(vector<int>& nums) {\n\tint n = nums.size();\n\tif (n == 1)\n\t\treturn nums.back() * nums.back();\n\tvector<long long> pregcd(n, nums[0]), prelcm(n, nums[0]);\n\tvector<long long> postgcd(n, nums.back()), postlcm(n, nums.back());\n\tfor (int i = 1; i < n; i++) {\n\t\tpregcd[i] = __gcd(pregcd[i - 1], 1LL * nums[i]);\n\t\tprelcm[i] = lcm(prelcm[i - 1], 1LL * nums[i]);\n\t}\n\tfor (int i = n - 2; i >= 0; i--) {\n\t\tpostgcd[i] = __gcd(postgcd[i + 1], 1LL * nums[i]);\n\t\tpostlcm[i] = lcm(postlcm[i + 1], 1LL * nums[i]);\n\t}\n\tlong long res = max( { pregcd.back() * prelcm.back(),\n\t\t\t\t\t\t   pregcd[n - 2] * prelcm[n - 2],\n\t\t\t\t\t\t   postgcd[1] * postlcm[1] } );\n\tfor (int i = 1; i + 1 < n; i++) {\n\t\tres = max(res, __gcd(pregcd[i - 1], postgcd[i + 1]) *\n\t\t\t\t\t   lcm(prelcm[i - 1], postlcm[i + 1]));\n\t}\n\treturn res;\n}\n```
['Array', 'Math', 'Greedy', 'C', 'C++']