Easiest || C++ || Beginer Friendly 🏆
Intuition\n Describe your first thoughts on how to solve this problem. \nThe factor score is the product of LCM and GCD of the elements in the array. Removing d
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe factor score is the product of LCM and GCD of the elements in the array. Removing different elements will change the LCM and GCD, so we need to check each possibility to find the maximum score.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Calculate LCM and GCD: For the entire array, compute the LCM and GCD.\n2. Remove Each Element: For each element in the array, compute the LCM and GCD of the remaining elements.\n3. Maximize Factor Score: Calculate the factor score for each configuration and track the maximum score found.\n4. Return the Result: Finally, return the highest factor score.\n\n# Complexity\n- Time complexity:\uD835\uDC42(n^2)\nWe loop through each element (to remove it) and then loop through the rest to calculate LCM and GCD, resulting in quadratic time complexity.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long lhlp(vector<int>nums, int x){\n        long long ans =-1;\n        for(int i=0;i<nums.size();i++){\n            if(i == x)continue;\n            if(ans == -1)ans = nums[i];\n            else ans = (ans*nums[i])/gcd(static_cast<long long>(ans),static_cast<long long>(nums[i]));\n        }\n        return ans;\n    }\n    int ghlp(vector<int>nums, int x){\n        int ans =  -1;\n        for(int i=0;i<nums.size();i++){\n            if(i ==x)continue;\n            if(ans == -1)ans = nums[i];\n            else\n                ans = gcd(ans,nums[i]);\n            if(ans ==1)break;\n        }\n        return ans;\n    }\n    long long maxScore(vector<int>& nums) {\n     int n = nums.size();\n     //fs = lcm * gcd of all n elem\n     // return max(fs) --> remove 1 elem from it   \n     //if n == 0 fs =0;\n     if(n ==0 )return 0;\n     if(n ==1)return nums[0]*nums[0];\n     sort(nums.begin(), nums.end());\n     long long fs = lhlp(nums,-1)*ghlp(nums,-1);\n     for(int i=0;i<nums.size();i++){\n        long long l1 = lhlp(nums,i);\n        int g1 = ghlp(nums,i);\n        long long f2 = l1*g1;\n        fs = max(fs, f2);\n     }\n     return fs;\n    }\n};\n\n\n\n\n//4 20 4 6 15\n//4 4 6 15 20\n```
['C++']