Easy Approach C++,100% accepted solution
Intuition\n### Brute force: \nUse two loops to find the solution. However, this would be inefficient for large arrays.\n\n### Optimized approach:\n\n- Use prefi
# Intuition\n### Brute force: \nUse two loops to find the solution. However, this would be inefficient for large arrays.\n\n### Optimized approach:\n\n- Use prefix and suffix arrays.\n- First, calculate the gcd and lcm of all the elements ahead of the  current index and store them in arrays using a loop.\n- Then, iterate through the array and keep storing the results to compute the maximum score.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize Variables:\n\n    - gcdbehind to 0, which will keep track of the gcd of elements before the current index.\n    - lcmbehind to 1, which will keep track of the lcm of elements before the current index.\n    - gcdahead to 0, which will be used to store the gcd of elements after the current index.\n    - lcmahead to 1, which will be used to store the lcm of elements after the current index.\n    - ans to 0, which will store the maximum score.\n2. Create Prefix Arrays:\n\n    - gcdah to store the gcd of all elements after the current index.\n    - lcmah to store the lcm of all elements after the current index.\n3. Compute Prefix Arrays:\n\n    - Traverse the array from the end to the beginning to populate   gcdah and lcmah.\n4. Iterate Through the Array:\n\n    - For each index, compute two temporary scores using the prefix and suffix values.\n    - Update gcdbehind and lcmbehind with the current element.\n    - Update ans with the maximum of the current scores.\n5. Return the Result:\n    - Return the value of ans.\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long maxScore(vector<int>& nums) {\n        int n = nums.size();\n        if (n == 0) {\n            return 0;\n        }\n        long long gcdbehind = 0;\n        long long lcmbehind = 1;\n        long long gcdahead = 0;\n        long long lcmahead = 1;\n        long long ans = 0;\n        vector<long long> gcdah(n, 1);\n        vector<long long> lcmah(n, 1);\n\n        for (int i = n - 1; i >= 0; --i) {\n            gcdah[i] = gcdahead;\n            lcmah[i] = lcmahead;\n            gcdahead = gcd(gcdahead, nums[i]);\n            lcmahead = lcm(lcmahead, nums[i]);\n        }\n\n        for (int i = 0; i < n; ++i) {\n            long long temp1 =\n                gcd(gcdbehind, gcdah[i]) * lcm(lcmbehind, lcmah[i]);\n            lcmbehind = lcm(lcmbehind, nums[i]);\n            gcdbehind = gcd(gcdbehind, nums[i]);\n            long long temp2 =\n                gcd(gcdbehind, gcdah[i]) * lcm(lcmbehind, lcmah[i]);\n            ans = max({ans, temp1, temp2});\n        }\n        return ans;\n    }\n};\n```
['C++']