Prefix + Suffix
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nPrefix + Suffix\n\n# Co
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPrefix + Suffix\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)$$ -->\nwhere $n$ is the length of the $nums$ array\n\n# Code\n```rust []\nimpl Solution {\n    pub fn max_score(nums: Vec<i32>) -> i64 {\n        let n = nums.len();\n\n        let mut fd = vec![nums[0] as i64; n];\n        let mut fm = vec![nums[0] as i64; n];\n\n        let mut bd = vec![nums[n-1] as i64; n];\n        let mut bm = vec![nums[n-1] as i64; n];\n\n        for i in 1..n {\n            fd[i] = Self::gcd(fd[i-1], nums[i] as i64);\n            fm[i] = Self::lcm(fm[i-1], nums[i] as i64);\n\n            bd[n-i-1] = Self::gcd(bd[n-i], nums[n-i-1] as i64);\n            bm[n-i-1] = Self::lcm(bm[n-i], nums[n-i-1] as i64);\n        }\n\n        let mut r = (fd[n-1] * fm[n-1]);\n\n        if n >= 2 {\n            r = r.max(fd[n-2] * fm[n-2]);\n            r = r.max(bd[1] * bm[1])\n        }        \n\n        for i in (2..n).rev() {\n            let mut d = Self::gcd(bd[i], fd[i-2]);\n            let mut m = Self::lcm(bm[i], fm[i-2]);       \n\n            r = r.max(d * m);            \n        }\n\n        r\n    }\n\n    pub fn gcd(a: i64, b: i64) -> i64 {\n        if a % b == 0 {\n            return b;\n        }\n\n        Self::gcd(b, a % b)\n    }\n\n    pub fn lcm(a: i64, b: i64) -> i64 {\n        (a * b) / Self::gcd(a, b)\n    }\n}\n```
['Array', 'Math', 'Number Theory', 'Rust']