Brute-forcing solution by slicing and calculating LCM and GCD for remaining elements
IntuitionWe'll approach this problem in a rather brute-"forcish" fashion. We'll ignore the element at each position in nums and calculate the LCM and GCD for th
# Intuition

We'll approach this problem in a rather brute-"forcish" fashion. We'll ignore the element at each position in `nums` and calculate the LCM and GCD for the remaining elements while keeping track of the maximum value.

# Approach

The LCM and GCD of a single number are the number itself:
```py
if L == 1:
    return nums[0]**2
```

The factor score of an empty array is 0:
```py
if L == 0:
    return 0
```


The GCD is associative, therefore `GCD(x, y, z)` is the same as:
```
GCD(GCD(x, y), z) 
```

Therefore, we can simply use `reduce()` to process all the elements and use the built-in `lcm()` and `gcd()` as our *reducer function*:
```py
def _lcm(xs):
    return reduce(lambda x, y: x * y // gcd(x, y), xs)

def _gcd(xs):
    return reduce(gcd, xs)
```



We'll step over each position of the array and slice of the prefix and suffix at our current index `i` without the element at `i`:
```py
slc = nums[:i] + nums[i + 1:]
```

We then pass this slice to our `_lcm()` and `_gcm()` and keep track of the maximum value.

Since we're allowed to remove **at most** one element, so we may get the maximum factor score by not removing an element from the array at all, therefore we'll initialize our *factor score result* with the score that we obtain we considering all the elements in `nums`:
```py
fcx = _lcm(nums) * _gcd(nums)
```

# Complexity
- Time complexity: $$O(n^2)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maxScore(self, nums: List[int]) -> int:
        L = len(nums)
        if L == 0:
            return 0
        if L == 1:
            return nums[0]**2

        def _lcm(xs):
            return reduce(lambda x, y: x * y // gcd(x, y), xs)

        def _gcd(xs):
            return reduce(gcd, xs)

        fcx = _lcm(nums) * _gcd(nums)
        
        for i in range(L):
            slc = nums[:i] + nums[i + 1:]
            x = _lcm(slc)
            y = _gcd(slc)
            fcx = max(fcx, x * y)

        return fcx

```
['Number Theory', 'Python3']