Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make Array Equalindromic

Minimum Cost to Make Array Equalindromic asks you to choose one positive palindromic value for every array element and return the least total cost of changing the values to it.

Statement

You are given an integer array nums of length n.

In one operation, you can select any index i and replace nums[i] with a positive palindromic integer x. The cost associated with this operation is ∣|nums[i] - x∣|.

An array is defined as equalindromic if all its elements are equal to the same positive palindromic integer.

Return the minimum total cost needed to make the array nums equalindromic.

Note: A palindromic number is a positive integer that reads the same forwards and backwards.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make Array Equalindromic

Minimum Cost to Make Array Equalindromic asks you to choose one positive palindromic value for every array element and return the least total cost of changing the values to it.

Statement

You are given an integer array nums of length n.

In one operation, you can select any index i and replace nums[i] with a positive palindromic integer x. The cost associated with this operation is ∣|nums[i] - x∣|.

An array is defined as equalindromic if all its elements are equal to the same positive palindromic integer.

Return the minimum total cost needed to make the array nums equalindromic.

Note: A palindromic number is a positive integer that reads the same forwards and backwards.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9