Bird
Raised Fist0

What is the output of the job scheduling code below when given a single job with startTime=[5], endTime=[5], profit=[10]?

medium🧾 Code Trace Q4 of Q15
Dynamic Programming: Knapsack - Maximum Profit in Job Scheduling
What is the output of the job scheduling code below when given a single job with startTime=[5], endTime=[5], profit=[10]?
A0
B10
C5
DError due to indexing
Step-by-Step Solution
Solution:
  1. Step 1: Sort single job

    Only one job: (5,5,10), ends=[5]
  2. Step 2: Calculate dp[0]

    idx = bisect_right([5], 5-1=4) -1 = bisect_right([5],4)-1=0-1=-1; take=10+0=10; skip=0; dp[0]=max(10,0)=10
  3. Step 3: Return dp[-1]

    dp[-1]=dp[0]=10
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Single job profit returned correctly [OK]
Quick Trick: Single job dp equals its profit [OK]
Common Mistakes:
MISTAKES
  • Miscomputing binary search index
  • Assuming empty dp for single job
Trap Explanation:
PITFALL
  • Some candidates expect error or zero profit for single job edge case.
Interviewer Note:
CONTEXT
  • Tests boundary conditions and indexing correctness.
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