Short Ruby solution. No libraries.
Intuition\nStraight forward\n\n# Approach\nBrute-force\n\n# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(1)\n\n# Code\nruby []\n# @param {In
# Intuition\nStraight forward\n\n# Approach\nBrute-force\n\n# Complexity\n- Time complexity:\n$$O(n^2)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```ruby []\n# @param {Integer[]} nums\n# @return {Integer}\ndef max_score(nums)\n  n = nums.size    \n  return 0 if n == 0\n  return nums[0] * nums[0] if n == 1\n  \n  max = reducer(:lcm, nums, 1) * reducer(:gcd, nums, 1)\n\n  nums.each_with_index do |v, idx|\n    (nums[0], nums[idx]) = [nums[idx], nums[0]] # swap a head\n    max = [reducer(:lcm, nums) * reducer(:gcd, nums), max].max\n  end\n\n  max\nend\n\ndef gcd(a, b)\n  b == 0 ? a : gcd(b, a % b)\nend\n\ndef lcm(a, b)\n  a == 0 || b == 0 ? a : a * b / gcd(a, b)\nend\n\ndef reducer(mtd, arr, shift = 0)\n  arr[(2 - shift)..].reduce(arr[1 - shift]) { |el, res| res = method(mtd).call(res, el) }\nend\n```
['Ruby']