FastPrepUnequal Block Structure
Problem · Array

Unequal Block Structure

Learn this problem
â—Ź MediumWeride logoWerideFULLTIMEOA

Problem statement

You are given two arrays, heights and cost, of equal length. You may increase the height of block i by any nonnegative integer number of units. Each unit added to that block costs cost[i].

Choose the increases so that no two adjacent blocks have equal final heights. Return the minimum possible total cost.

Function

getMinCost(heights: int[], cost: int[]) → long

Examples

Example 1

heights = [2, 2, 3]cost = [4, 1, 5]return = 2

Increase the second block by 2 units. The final heights become [2, 4, 3], and the total cost is 2 * 1 = 2.

Constraints

  • 1 <= heights.length = cost.length <= 2 * 10^6
  • 1 <= heights[i], cost[i] <= 10^9

More Weride problems

drafts saved locally
public long getMinCost(int[] heights, int[] cost) {
    // Write your code here
}
heights[2, 2, 3]
cost[4, 1, 5]
expected2
checking account