Problem · Array

Minimum Adjacent Merges to Form a Palindrome

Learn this problem
MediumArista Networks logoArista NetworksFULLTIMEOA

Problem 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[]) → int

Examples

Example 1

nums = [12,14,8,13,5]return = 3

Three adjacent merges can produce [26, 26], which is a palindrome.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9

More Arista Networks problems

drafts saved locally
public int minMergesToPalindrome(int[] nums) {
    // Write your solution here.
}
nums[12,14,8,13,5]
expected3
checking account