My Solution
\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the vector `nums`\n */\nclass Solution {\n public:\n  long long maxSco
```\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the vector `nums`\n */\nclass Solution {\n public:\n  long long maxScore(const vector<int> &nums) {\n    const int n = static_cast<int>(nums.size());\n    long long left_gcd[n];\n    memset(left_gcd, 0, sizeof(left_gcd));\n    left_gcd[0] = nums.front();\n    long long left_lcm[n];\n    memset(left_lcm, 0, sizeof(left_lcm));\n    left_lcm[0] = nums.front();\n    \n    for (int i = 1; i < n; ++i) {\n      left_gcd[i] = get_gcd(left_gcd[i - 1], nums[i]);\n      left_lcm[i] = get_lcm(left_lcm[i - 1], nums[i]);\n    }\n    \n    long long ret = left_gcd[n - 1] * left_lcm[n - 1];\n    long long right_gcd = 0;\n    long long right_lcm = 1;\n    for (int i = n - 1; i > 0; --i) {\n      ret = max(ret, get_gcd(left_gcd[i - 1], right_gcd) * get_lcm(left_lcm[i - 1], right_lcm));\n      right_gcd = get_gcd(right_gcd, nums[i]);\n      right_lcm = get_lcm(right_lcm, nums[i]);\n    }\n    ret = max(ret, right_gcd * right_lcm);\n    return ret;\n  }\n  \n private:\n  long long get_gcd(const long long a, const long long b) {\n    if (a == 0) {\n      return b;\n    }\n    return get_gcd(b % a, a);\n  }\n  \n  long long get_lcm(const long long a, const long long b) {\n    const long long gcd = get_gcd(a, b);\n    return (a / gcd) * b;\n  }\n};\n```
[]