Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Jobs are (start, end, profit) triples: (1,4,5), (3,5,1), (0,6,8), (4,7,4), (3,8,6), (5,9,3), (6,10,2), (8,11,4). One machine can run a set of jobs when no two overlap; a job ending at t and one starting at t are compatible. What is the maximum total profit?

  1. A. 9
  2. B. 13
  3. C. 15
  4. D. 33

Correct answer: B. 13

Weighted interval scheduling sorts by end time and uses dp[i] = max(dp[i-1], profit_i + dp[last job compatible with i]), with binary search for the predecessor. Exhaustive checking of all subsets confirms the optimum 13; summing every profit ignores the overlap rule.

More Coding Interview Problems questions

Exams that ask this topic