Python: Beats 100%
Intuition\nCreate functions for lcn(nums) and gcd(nums), calculate the maxfactor. Try removing the numbers one by one from the list and check whether the update
# Intuition\nCreate functions for lcn(nums) and gcd(nums), calculate the maxfactor. Try removing the numbers one by one from the list and check whether the updated maxfactor exceeds the running maximum\n\n# Approach\nThe idea is to convert the list of numbers into a matrix of size 11xn, where each row will contain the powers of each number from the list corresponding to a prime number under 30. nRows = 11 because there are 11 prime numbers under 30. Then for gcd we need to take the minimums for each row, and for lcn the maximums. After that we raise the prime numbers into these powers and multiply together. Removing one original number from the list is the same as removing one column from the grand matrix and recalculating the mins/maxs and gcd/lcn.\n\n# Complexity\n- Time complexity:\nBeats 100%\n\n- Space complexity:\nBeats 100%\n\n# Code\n```python []\nclass Solution(object):\n    def gcd(self, pows, prime_numbers):\n        result = 1\n        for ipow, powstr in enumerate(pows):\n            minpow = min(powstr)\n            result*=(prime_numbers[ipow]**minpow)\n        return result\n\n    def lcn(self, pows, prime_numbers):\n        result = 1\n        for ipow, powstr in enumerate(pows):\n            maxpow = max(powstr)\n            result*=(prime_numbers[ipow]**maxpow)\n        return result\n\n    def maxScore(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        prime_numbers = [2,3,5,7,11,13,17,19,23,29]\n        pows = [[] for i in range(len(prime_numbers))]\n        if len(nums)==1:\n            return nums[0]*nums[0]      \n        for i_prime in range(len(prime_numbers)):\n            for num_i in nums:\n                power = 0\n                while num_i % prime_numbers[i_prime]==0:\n                    num_i/=prime_numbers[i_prime]\n                    power+=1\n                pows[i_prime].append(power)\n        maxfactor = self.gcd(pows, prime_numbers)*self.lcn(pows, prime_numbers)\n        for inum in range(len(nums)):\n            new_pows = [pows_i[:] for pows_i in pows]\n            for new_pows_i in new_pows:\n                new_pows_i.pop(inum)\n            new_factor = self.gcd(new_pows, prime_numbers)*self.lcn(new_pows, prime_numbers)\n            if new_factor>maxfactor:\n                maxfactor = new_factor\n        return maxfactor\n\n```
['Python']