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?
- A. 9
- B. 13
- C. 15
- 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
- Intervals [0,4], [3,7], [6,10], [2,6], [9,12], [1,3] are available. What is the minimum number of them needed to cover the whole segment…
- Problem: A directed road map has junctions 0..4 and roads (u, v, w): (0,1,1), (0,2,1), (1,3,1), (2,3,1), (3,4,1), (1,2,1). Count the…
- Problem: A grid of 0/1 costs (a cell costs its value when you enter it) is solved by 0-1 BFS from the top-left cell to the bottom-right…
- Problem: Junctions 1..6 form a precedence graph with edges 4 to 1, 3 to 1, 2 to 5 (an edge a to b means a must come before b). Kahn's…
- Problem: Kruskal's algorithm with union-find is run on 5 nodes (0..4) with weighted edges (4,0,1), (1,1,2), (3,0,2), (2,2,3), (7,3,4)…
- Problem: Count the subsets (including the empty subset) of {1, 2, 3, 4, 5, 6} whose sum is divisible by 3. python a = [1, 2, 3, 4, 5, 6]…