LeetCode solutions

3593. Find the Maximum Factor Score of Array

My accepted Python solution to LeetCode problem 3593, Find the Maximum Factor Score of Array, running in 45ms.

  • Difficulty: Medium
  • Python
  • Runtime 45ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 45ms, memory 17.4MB, accepted 2025-12-30.

python
class Solution:
    def maxScore(self, nums: List[int]) -> int:
        from math import gcd, lcm
        from functools import reduce
        
        def factor_score(arr):
            if not arr:
                return 0
            g = reduce(gcd, arr)
            l = reduce(lcm, arr)
            return g * l
        
        n = len(nums)
        if n == 1:
            return nums[0] * nums[0]
        
        # Try removing no element
        result = factor_score(nums)
        
        # Try removing each element
        for i in range(n):
            arr = nums[:i] + nums[i+1:]
            result = max(result, factor_score(arr))
        
        return result

Source