Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Tasks are (deadline, duration): (3, 1), (2, 2), (4, 3), (5, 2), (1, 1). Tasks run one after another from time 0 without preemption, and a task finishes on time if its finish time is at most its deadline. What is the largest number of tasks that can all finish on time?
- A. 3
- B. 4
- C. 2
- D. 1
Correct answer: C. 2
Moore-Hodgson style: sort by deadline, add each task to the schedule, and when the running finish time passes a deadline, remove the longest task scheduled so far. Brute force over all subsets confirms the count.
More Coding Interview Problems questions
- Split the array [7, 2, 5, 10, 8, 4, 6] into 3 non-empty contiguous parts so that the largest part sum is as small as possible. What is…
- Sorted arrays A = [1, 4, 6, 9] and B = [2, 3, 7, 10]. How many pairs (x from A, y from B) have 8 <= x + y <= 12?
- Array a = [1, 2, 3, 1, 2, 3, 1]. How many contiguous subarrays of length at least 2 have the sum of the elements at even offsets (0, 2, 4…
- Array [1, 2, 3, 4, 5, 6, 7, 0]. How many index pairs i < j satisfy (a[i] OR a[j]) = 7?
- Coins have values 1, 3, 9, 27, 81, ... (powers of three, unlimited supply). What is the minimum number of coins needed to pay exactly 41?
- Array [5, 1, 4, 6, 2, 8, 3, 7]. What is the length of the longest contiguous subarray whose maximum minus minimum is at most 3?