Bird
Raised Fist0

Given the dp array after processing 5 jobs sorted by end time: dp = [20, 50, 50, 120, 150], which job was most likely included last to achieve dp[4] = 150?

hard🔄 Reverse Engineer Q9 of Q15
Dynamic Programming: Knapsack - Maximum Profit in Job Scheduling
Given the dp array after processing 5 jobs sorted by end time: dp = [20, 50, 50, 120, 150], which job was most likely included last to achieve dp[4] = 150?
AJob with profit 60 ending latest
BJob with profit 20 ending earliest
CJob with profit 100 ending in the middle
DJob with profit 70 ending second latest
Step-by-Step Solution
Solution:
  1. Step 1: Analyze dp progression

    dp[4]=150 is max profit including jobs up to index 4.
  2. Step 2: Identify last job contributing to dp[4]

    Since dp[3]=120 and dp[4]=150, last job likely adds 30 profit (150-120=30) or more if combined with compatible jobs.
  3. Step 3: Match profit and end time

    Job with profit 60 ending latest fits last job increasing total profit to 150.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Last job with profit 60 raises dp from 120 to 150 [OK]
Quick Trick: Last dp increment matches last job profit [OK]
Common Mistakes:
MISTAKES
  • Picking earliest job
  • Ignoring dp incremental differences
Trap Explanation:
PITFALL
  • Candidates confuse dp indices with job profits or order.
Interviewer Note:
CONTEXT
  • Tests ability to reason backwards from DP table to input jobs.
Master "Maximum Profit in Job Scheduling" in Dynamic Programming: Knapsack

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Dynamic Programming: Knapsack Quizzes