Max Score with Brute Force lcm*gcd
Intuition\n Describe your first thoughts on how to solve this problem. \nAs the Questions says that we find the maximum score that is equal to product of lcm of
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the Questions says that we find the maximum score that is equal to product of lcm of array elements and gcd of the array elements and we can remove at most one element.\nThen first thing which come in my mind that according to constraint solution will be accepeted in 0(n^2) so I create all possible array with excluding the one element and first array with non exclude any element and then calculate, gcd and lcm of array and find product of lcm and gcd and store the maximum value of product in ans.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nfirt run a  loop i = -1 to i < n  and in loop create a vector res\nand run another loop inside the first loop and if i != j then store that element in the res. Thus we find all possible vector of elements\n\nmake a function max_fector(res) and store the value of the function in p and find the ans =  max(ans , p).\n\nIn max_factor function calculate the gcd of the array element using Euclidian Algorithm of gcd and calculate lcm of the array elements in another function lcm_arr with parameters res vector and starting index 0. Since lcm of two numbers a , b is equal to the (a*b)/gcd(a,b), Thus I find lcm of all array elements which is store in lcm variable and ans = lcm*gcd of array and return ans in max_factor.\nFinally in maxScore function maximize the score and return as the final answer in maxScore function.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    I run two loop of n*n = o(n^2)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n   I use a vector which store n - 1 elements minimum and n elements   maximum so space complexity is o(n).\n\n# Code\n```cpp\n\nclass Solution {\n\nprivate:\n\nlong long gcd(long long a , long long b){\n     if(b == 0)return a;\n     return gcd(b , a%b);\n}\n\nlong long lcm_arr(vector<long long>&res , int ind){\n      if(ind == res.size()-1)return res[ind];\n      long long a = res[ind];\n      long long b = lcm_arr(res , ind+1);\n      return (a*b/gcd(a,b));\n\n}\n\nlong long max_factor(vector<long long>&res){\n      \n       long long gcd1 = res[0];\n       for(int i = 1 ; i < res.size() ; i++){\n             gcd1 = gcd(gcd1 , res[i]);\n       }\n       long long lcm = lcm_arr(res , 0);\n\n       long long ans = lcm*gcd1;\n       return ans;\n}\n\npublic:\n    long long maxScore(vector<int>& nums) {\n\n        if(nums.size()==1)return nums[0]*nums[0];\n        \n          long long n = nums.size();\n          long long ans = 0;\n\n          for(int  i = -1 ; i < n ; i++){\n               vector<long long>res;\n\n                for(int j = 0 ; j < n ; j++){\n                      if(i != j)res.push_back(nums[j]);\n                }\n\n               long long p = max_factor(res);\n               ans = max(ans , p);\n          }\n          return ans;\n    }\n};\n```
['C++']