Beats 100% || Constant Space
Complexity\n- Time complexity:\nO(n^2)\n- Space complexity:\nO(1)\n\n# Code\njava []\nclass Solution {\n    public long gcd(long m, long n){\n        while(n !=
# Complexity\n- Time complexity:\nO(n^2)\n- Space complexity:\nO(1)\n\n# Code\n```java []\nclass Solution {\n    public long gcd(long m, long n){\n        while(n != 0){\n            long gcd = m % n;\n            m = n;\n            n = gcd;\n        }\n\n        return m;\n    }\n    public long lcm(long m, long n){\n        if (m == 0 || n == 0) return 0;\n        return ((m * n)/gcd(m, n));\n    }\n    public long maxScore(int[] nums) {\n        if(nums.length == 0) return 0;   \n        if(nums.length == 1) return nums[0]*nums[0];\n\n        long findLcm = nums[0], findGcd = nums[0];\n\n        //without removing\n        for(int i = 1; i < nums.length; i++){\n            findLcm = lcm(findLcm, nums[i]);\n            findGcd = gcd(findGcd, nums[i]);\n        }\n        long withoutRemoving = findLcm * findGcd;\n\n        long maxWithRemoving = 0;\n        for(int i = 0; i < nums.length; i++){\n            long solveLcm = -1, solveGcd = -1;\n            for(int j = 0; j < nums.length; j++){\n                if(i == j) continue;\n\n                if(solveLcm == -1){\n                    solveLcm = nums[j];\n                    solveGcd = nums[j];\n                }\n                else{\n                    solveLcm = lcm(solveLcm, nums[j]);\n                    solveGcd = gcd(solveGcd, nums[j]);\n                }\n            }\n\n            long withRemoving = solveLcm * solveGcd;\n            maxWithRemoving = Math.max(withRemoving, maxWithRemoving);\n        }\n\n        return Math.max(withoutRemoving, maxWithRemoving);\n    }\n}\n```
['Java']