Profitable Schemes

HardDynamic Programming2d dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A gang has n members. Crime i needs exactly group[i] members and yields profit[i]. A member who takes part in one crime cannot take part in another. A **scheme** is any subset of crimes (the empty subset included) that uses at most n members in total and yields a combined profit of at least minProfit. Return the number of schemes modulo 10^9 + 7.

Examples

Input: n = 5, minProfit = 3, group = [2,2], profit = [2,3]
Output: 2
Crime 1 alone (profit 3), or crimes 0 and 1 (4 members, profit 5).
Input: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]
Output: 7
Every non-empty subset works: each single crime already earns at least 5 and all three use exactly 10 members.

Constraints

  • 1 <= n <= 100
  • 0 <= minProfit <= 100
  • 1 <= group.length <= 100
  • group.length == profit.length
  • 1 <= group[i] <= 100
  • 0 <= profit[i] <= 100

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More 2d dp problems