Problem · Array
Minimum Adjacent Merges to Form a Palindrome
Learn this problemProblem statement
In one operation, choose two adjacent array elements and replace them with their sum. Return the minimum number of operations needed to make the resulting array a palindrome.
Function
minMergesToPalindrome(nums: int[]) → intExamples
Example 1
nums = [12,14,8,13,5]return = 3Three adjacent merges can produce [26, 26], which is a palindrome.
Constraints
1 <= nums.length <= 10^51 <= nums[i] <= 10^9