Combine Numbers
For this problem we ask you to compute the largest value that can be created by combining subarrays.
Subarrays can be combined if 2
adjacent numbers in the array share a common factor greater than 1
, then the 2 numbers can be summed into 1 number.
Using this operation determine the largest value that can be created.
Input
nums
: array of numbers
Output
value of the largest value that can be created
Examples
Example 1:
Input:
nums = [2, 1, 2, 4, 2, 4]
Output: 12
Explanation:
[2, 1, 2, 4, 2, 4] -> [2, 1, 6, 2, 4] -> [2, 1, 6, 6] -> [2, 1, 12]
Constraints
1 <= nums.length <= 500
1 <= nums[i] <= 100000