Cpp | Beats 100 %
Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy\n# Approach\nCreate left and right array for gcd and lcm \n Describe your approa
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy\n# Approach\nCreate left and right array for gcd and lcm \n<!-- Describe your approach to solving the problem. -->\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    typedef long long ll;\n    ll LCM(ll a,ll b){\n        ll gcd=__gcd(a,b);\n        return  (a/gcd)*b;\n    }\n    long long maxScore(vector<int>& nums) {\n        int n=nums.size();\n        vector<ll>left_gcd(n);\n        vector<ll>right_gcd(n);\n        left_gcd[0]=nums[0];\n        for(int i=1;i<n;i++){\n            left_gcd[i]=__gcd(left_gcd[i-1],(ll)nums[i]);\n        }\n        right_gcd[n-1]=nums[n-1];\n        for(int i=n-2;i>=0;i--){\n            right_gcd[i]=__gcd(right_gcd[i+1],(ll)nums[i]);\n        }\n        vector<ll>left_lcm(n);\n        vector<ll>right_lcm(n);\n        left_lcm[0]=nums[0];\n        for(int i=1;i<n;i++){\n            left_lcm[i]=LCM(left_lcm[i-1],nums[i]);\n        }\n        right_lcm[n-1]=nums[n-1];\n        for(int i=n-2;i>=0;i--){\n            right_lcm[i]=LCM(right_lcm[i+1],nums[i]);\n        }\n        if(n==1)return left_gcd[0]*left_lcm[0];\n        ll ans=max({right_gcd[1]*right_lcm[1],left_lcm[n-2]*left_gcd[n-2]});\n        for(int i=1;i<n-1;i++){\n            ll gcd=__gcd(left_gcd[i-1],right_gcd[i+1]);\n            ll lcm=LCM(left_lcm[i-1],right_lcm[i+1]);\n            ans=max(ans,gcd*lcm);\n        }\n        ll res=left_lcm[n-1]*left_gcd[n-1];\n        ans=max(ans,res);\n        return ans;\n    }\n};\n```
['C++']