Time: O(n) , Space : O(n) , 2 pass , C++
Intuition\nIterate through the array , leave  current element and calculate gcd and lcm for all the remaining elements.\nBut it would take O(n^2).\nIf you look 
# Intuition\nIterate through the array , leave  current element and calculate gcd and lcm for all the remaining elements.\nBut it would take O(n^2).\nIf you look closely you will find redundent work , why can\'t we calculate in the starting and save these answers in suffix arrays.\n\nNo need to create prefix array we can use variables to store lcm and gcd from start.\n\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\no(n)\n\n# Code\n```cpp []\n# define ll long long\nclass Solution {\npublic:\n    long long maxScore(vector<int>& nums) {\n\n          int n = nums.size();\n\n        if(n==1)\n        return nums[0]*nums[0];\n\n\n        vector<ll> gcdFromBack(n);\n        vector<ll> lcmFromBack(n);\n          ll g =0, l=1;\n\n         for(int i=n-1 ;i>=0 ;--i)\n       {  \n         g= __gcd(g, (ll)nums[i]);\n         l = (l/__gcd(l,(ll)nums[i])*nums[i]);\n         gcdFromBack[i] =g ;\n         lcmFromBack[i] = l;\n         \n       }\n\n        ll gmax = g*l;\n       g=0 , l=1;\n      \n\n       for(int i=0 ;i<n ;i++)\n       {     \n           ll gmerge = i== n-1?g: __gcd(g, gcdFromBack[i+1] );\n           ll lmerge = i== n-1?l: (l /__gcd(l ,lcmFromBack[i+1]) * lcmFromBack[i+1]); // to avoid overflow , l is a bigger so divide it alone by gcd\n         gcdFromBack[i] =g ;\n           gmax = max (gmax , gmerge*lmerge );\n \n         g= __gcd(g, (ll)nums[i]);\n         l = (l*nums[i])/__gcd(l,(ll)nums[i]);\n         \n       }\n     \n     return gmax ;\n    \n    }\n};\n```
['C++']