Brute Force + Prefix and Suffix Array
Intuition\n Describe your first thoughts on how to solve this problem. \nSince we have the property that gcd(a,b,c) = gcd (gcd(a,b),c), and same for lcm, we can
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince we have the property that gcd(a,b,c) = gcd (gcd(a,b),c), and same for lcm, we can build prefix and suffix gcd and lcm array to store these value beforehand.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nloop through the array with skip index, the score after removal is gcd * lcm of (prefix[skip -1] and  sufix[skip+1]). Maintain the maxScore after each loop.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> O(nlogn)\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Code\n```java []\nclass Solution {\n    public long findGcd(long a, long b){\n        while (b != 0){\n            long temp = b;\n            b = a % b;\n            a = temp;\n        }\n        return a;\n    }\n    public long findLcm(long a, long b){ \n        return (a * b) / findGcd(a,b);\n    }\n    public long maxScore(int[] nums) {\n        int n = nums.length;\n        if (n == 0) {\n            return 0;\n        }\n        if (n == 1){\n            return nums[0]*nums[0];\n        }\n        long[] preGcd = new long[n];\n        long[] sufGcd = new long[n];\n        long[] preLcm = new long[n];\n        long[] sufLcm = new long[n];\n\n        preGcd[0] = nums[0];\n        sufGcd[n-1] = nums[n-1];\n        preLcm[0] = nums[0];\n        sufLcm[n-1] = nums[n-1];\n\n        for (int i = 1; i < n; i++){\n            preGcd[i] = findGcd(preGcd[i-1], nums[i]);\n            \n            preLcm[i] = findLcm(preLcm[i-1], nums[i]);\n        }\n\n        for (int i = n - 2; i >= 0; i--){\n            sufGcd[i] = findGcd(sufGcd[i+1], nums[i]);\n            sufLcm[i] = findLcm(sufLcm[i+1], nums[i]);\n            //system.out.println("suf gcd and sf lcm is :" +sufGcd[1] + " "+ sufLcm[1]);\n        }\n\n        long maxScore = preGcd[n-1] * preLcm[n-1];\n\n        for (int skip = 0; skip < n;skip++){\n            long currScore;\n            if (skip == 0){\n                currScore = sufGcd[1] * sufLcm[1];\n                //System.out.println(sufGcd[1] + " "+ sufLcm[1]);\n                maxScore = Math.max(maxScore, currScore);\n                //System.out.println("currScore is :" + currScore);\n                continue;\n            }\n            if (skip == n - 1){\n                currScore = preGcd[n-2] * preLcm[n-2];\n                maxScore = Math.max(maxScore, currScore);\n                continue;\n            }\n            long gcd = findGcd(preGcd[skip-1], sufGcd[skip+1]);\n            long lcm = findLcm(preLcm[skip-1], sufLcm[skip+1]);\n            currScore =  gcd * lcm; \n            maxScore = Math.max(maxScore, currScore);\n        }\n        return maxScore;\n    }\n}\n```
['Java']