Problem · Array

Minimum Image Processing Cost

Learn this problem
MediumCitadelOA

Problem statement

You must process n images. Image i requires a filter on every day from startDay[i] through endDay[i], inclusive, and filtering that image costs filterCost[i] per day.

An exclusive offer allows you to apply a filter to all n images for discountPrice on a day. Determine the minimum total cost of processing all images, and return that cost modulo 10^9 + 7.

Function

getMinProcessingCost(filterCost: int[], startDay: int[], endDay: int[], discountPrice: int) → int

Examples

Example 1

filterCost = [2,3,4]startDay = [1,1,2]endDay = [2,3,4]discountPrice = 6return = 21

For filterCost = [2, 3, 4], startDay = [1, 1, 2], endDay = [2, 3, 4], and discountPrice = 6, the individual filtering costs by day are:

Daily individual filtering costs
DayImagesTotal cost
1[1, 2]2 + 3 = 5
2[1, 2, 3]2 + 3 + 4 = 9
3[2, 3]3 + 4 = 7
4[3]4

Using the all-images offer for 6 on days 2 and 3 is optimal. The final cost is 5 + 6 + 6 + 4 = 21, so its value modulo 10^9 + 7 is 21.

More Citadel problems

drafts saved locally
public int getMinProcessingCost(int[] filterCost, int[] startDay, int[] endDay, int discountPrice) {
  // write your code here
}
filterCost[2,3,4]
startDay[1,1,2]
endDay[2,3,4]
discountPrice6
expected21
checking account