Easy Approach with proper Explanation.
Intuition\nWhen tackling the problem of finding the maximum factor score of an integer array after potentially removing one element, my first thought was to lev
# Intuition\nWhen tackling the problem of finding the maximum factor score of an integer array after potentially removing one element, my first thought was to leverage the properties of GCD (Greatest Common Divisor) and LCM (Least Common Multiple). The factor score is defined as the product of the GCD and LCM of the array, so I realized I need to efficiently compute these values for the entire array and for each possible subset (after removing one element).\n\n# Approach\n1. I started by implementing **helper functions** to compute the GCD and LCM of two numbers. The GCD can be computed using the Euclidean algorithm, while the LCM is give by,\n``lcm(a, b) = (a * b)/gcd(a, b)``.\n\n2. I then calculated the overall GCD and LCM for the entire array. This gives me a baseline factor score.\n\n3. For each element in the array, I computed the GCD and LCM of the remaining elements (after removing the current element). I kept track of the maximum factor score found during this iteration.\n\n4. Finally, I returned the highest factor score obtained.\n\nThis method allows me to evaluate all possible configurations of the array efficiently, ensuring that I consider both cases **removing one element and keeping all elements.**\n\n# Complexity\n- **Time complexity**: The time complexity of this solution is **O(n^2)** in the worst case, where **n** is the number of elements in the input array. This is because for each of the **n** elements, we might need to compute the GCD and LCM of the remaining **n-1** elements, leading to a nested iteration.\n\n- **Space complexity**: The space complexity is **O(1)** since we are using a constant amount of space for storing variables and do not utilize any additional data structures that scale with input size.\n\n# Code\n```python\nfrom typing import List\n\nclass Solution:\n    def maxScore(self, nums: List[int]) -> int:\n        def gcd(a, b):\n            while b:\n                a, b = b, a % b\n            return a\n        \n        def lcm(a, b):\n            return (a * b) // gcd(a, b)\n        \n        n = len(nums)\n        if n == 1:\n            return nums[0] * nums[0]  # Special case for a single element\n        \n        # Calculate overall GCD and LCM\n        tot_gcd = nums[0]\n        tot_lcm = nums[0]\n        for num in nums[1:]:\n            tot_gcd = gcd(tot_gcd, num)\n            tot_lcm = lcm(tot_lcm, num)\n        \n        # Initial maximum score\n        max_score = tot_gcd * tot_lcm\n        \n        # Check scores for each possible removal\n        for i in range(n):\n            curr_gcd = 0\n            curr_lcm = 1\n            for j in range(n):\n                if i != j:\n                    curr_gcd = gcd(curr_gcd, nums[j])\n                    curr_lcm = lcm(curr_lcm, nums[j])\n            max_score = max(max_score, curr_gcd * curr_lcm)\n        \n        return max_score\n
['Math', 'Greedy', 'Python3']