Problem · Dynamic Programming

Maximum Profit from Ticket Bundles

Learn this problem
MediumIDFCFULLTIMEOA

Problem statement

You are given an integer array prices, where prices[i] is the profit from selling a bundle of exactly i + 1 tickets.

You must sell exactly m tickets. You may use any combination of bundle sizes, and each bundle size may be used multiple times.

Return the maximum total profit obtainable by selling exactly m tickets.

Function

maxTicketBundleProfit(prices: int[], m: int) → int

Examples

Example 1

prices = [10,70,30]m = 3return = 80

The best choice is one 1-ticket bundle and one 2-ticket bundle, for total profit 10 + 70 = 80. Selling one 3-ticket bundle gives profit 30.

Constraints

  • 1 <= m <= prices.length
  • prices.length gives the largest available ticket-bundle size.

More IDFC problems

drafts saved locally
public int maxTicketBundleProfit(int[] prices, int m) {
  // write your code here
}
prices[10,70,30]
m3
expected80
checking account