Problem · Array

Maximize Impression Value

Learn this problem
MediumInMobi logoInMobiFULLTIMEOA

Problem statement

You are given n ad impressions. Each impression has a value and a cost (its floor price), and you have a fixed budget.

Select a subset of the impressions whose total cost does not exceed budget. Return the maximum possible sum of their values.

Each impression may be selected at most once.

Function

maximizeImpressionValue(values: int[], costs: int[], budget: int) → long

Examples

Example 1

values = [10,40,30,50]costs = [5,4,6,3]budget = 10return = 90

Select the second and fourth impressions. Their total cost is 4 + 3 = 7, and their total value is 40 + 50 = 90. No other valid subset has a larger total value.

Constraints

  • 1 <= values.length = costs.length <= 1000
  • 1 <= budget <= 10^5
  • 1 <= values[i] <= 10^9
  • 1 <= costs[i] <= 10^5

More InMobi problems

drafts saved locally
public long maximizeImpressionValue(int[] values, int[] costs, int budget) {
    // write your code here
}
values[10,40,30,50]
costs[5,4,6,3]
budget10
expected90
checking account