Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Jobs are triples (start, end, weight): (1,3,2), (2,5,4), (4,6,3), (6,8,5), (5,9,6). Jobs may be chosen together only when one ends no later than the next begins. What is the maximum total weight?
- A. 12
- B. 9
- C. 19
- D. 10
Correct answer: D. 10
This is weighted interval scheduling: sort by end, use dp over the predecessor job that ends by the current start, and take the max of skipping or taking. Enumerating every subset gives the same optimum; for example (1,3), (4,6), (6,8) gives 2 + 3 + 5 = 10, and so does (2,5), (5,9).
More Coding Interview Problems questions
- Array a = [2, 1, 3, 4, 1, 2, 5, 1]. How many non-empty contiguous subarrays contain exactly as many odd numbers as even numbers?
- Array a = [4, -1, 2, -3, 5, -2, 1, 1, -4]. How many DISTINCT values appear among the sums of all non-empty contiguous subarrays?
- Array a = [6, 1, 8, 3, 9, 4, 2, 7, 5] has distinct values. How many ordered pairs (i, j) with i != j satisfy a[i] - a[j] = 4?
- For a = [1, 2, 3, 4, 5, 6, 7, 8], how many contiguous subarrays have a sum that is a multiple of 5?
- Array a = [2, 1, 5, 2, 3, 1, 4] has only positive values. How many non-empty contiguous subarrays have sum at most 9?
- Sorted values [1, 4, 6, 9, 13, 14, 18, 22] must be split into the fewest contiguous groups so that in every group the largest value minus…