Facebook Pixel

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 & Output
Input
nums — array of numbers
Output
value of the largest value that can be created
Example
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

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro