❓What if constrains were (1 <= nums.length <= 10^5)❓
\n\n### Approach\n1. Calculate Prefix and Suffix GCD/LCM Arrays:\n   - We need two arrays for each of GCD and LCM:\n     - prefixGCD and suffixGCD: Store the GC
\n\n### Approach\n1. **Calculate Prefix and Suffix GCD/LCM Arrays**:\n   - We need two arrays for each of GCD and LCM:\n     - `prefixGCD` and `suffixGCD`: Store the GCD of elements from the start up to each index, and from each index to the end.\n     - `prefixLCM` and `suffixLCM`: Store the LCM of elements from the start up to each index, and from each index to the end.\n   \n2. **Fill Prefix and Suffix Arrays**:\n   - For `prefixGCD` and `prefixLCM`, calculate GCD and LCM from left to right.\n   - For `suffixGCD` and `suffixLCM`, calculate GCD and LCM from right to left.\n\n3. **Calculate Maximum Factor Score After Removing Each Element**:\n   - For each element, calculate the GCD and LCM of the elements excluding the current element:\n     - If removing the first element, use `suffixGCD[1]` and `suffixLCM[1]`.\n     - If removing the last element, use `prefixGCD[n - 2]` and `prefixLCM[n - 2]`.\n     - For elements in between, combine `prefixGCD` and `suffixGCD`, and similarly for `prefixLCM` and `suffixLCM`.\n   - Compute the factor score (GCD * LCM) for each removal and track the maximum score.\n\n\n### Code\n```java\nclass Solution {\n    public long maxScore(int[] nums) {\n        int n = nums.length;\n        if (n == 1) return (long) nums[0] * nums[0];  \n\n        long[] prefixGCD = new long[n];\n        long[] suffixGCD = new long[n];\n        long[] prefixLCM = new long[n];\n        long[] suffixLCM = new long[n];\n        \n        prefixGCD[0] = nums[0];\n        prefixLCM[0] = nums[0];\n        for (int i = 1; i < n; i++) {\n            prefixGCD[i] = findGCD(prefixGCD[i - 1], nums[i]);\n            prefixLCM[i] = findLCM(prefixLCM[i - 1], nums[i]);\n        }\n        \n        suffixGCD[n - 1] = nums[n - 1];\n        suffixLCM[n - 1] = nums[n - 1];\n        for (int i = n - 2; i >= 0; i--) {\n            suffixGCD[i] = findGCD(suffixGCD[i + 1], nums[i]);\n            suffixLCM[i] = findLCM(suffixLCM[i + 1], nums[i]);\n        }\n        \n        long maxScore = prefixGCD[n - 1] * prefixLCM[n - 1];\n        for (int i = 0; i < n; i++) {\n            long gcdWithoutI = (i == 0) ? suffixGCD[1] : (i == n - 1 ? prefixGCD[n - 2] : findGCD(prefixGCD[i - 1], suffixGCD[i + 1]));\n            long lcmWithoutI = (i == 0) ? suffixLCM[1] : (i == n - 1 ? prefixLCM[n - 2] : findLCM(prefixLCM[i - 1], suffixLCM[i + 1]));\n            \n            long factorScore = gcdWithoutI * lcmWithoutI;\n            maxScore = Math.max(maxScore, factorScore);\n        }\n        \n        return maxScore;\n    }\n\n    public static long findGCD(long a, long b) {\n        if (b == 0) return a;\n        return findGCD(b, a % b);\n    }\n\n    public static long findLCM(long a, long b) {\n        return (a / findGCD(a, b)) * b;\n    }\n}\n```\n
['Array', 'Math', 'Number Theory', 'Prefix Sum', 'Java']