Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Tasks AAABBC must be scheduled one per time unit; two identical tasks need at least 2 idle-free units between them (cooldown k = 2, i.e. the same task may repeat only after 2 other tasks or idle slots). What is the minimum number of time units to run all six tasks?
- A. 6
- B. 9
- C. 18
- D. 7
Correct answer: D. 7
With the most frequent task A appearing 3 times, the frame is (3 − 1)·(k + 1) + 1 = 7 (A B C A B _ A), which exceeds the 6 tasks. Assuming no idling gives 6, using 3·(k + 1) forgets that the last block needs no cooldown (9), and making every one of the 6 tasks wait k slots gives 6·3 = 18.
More Coding Interview Problems questions
- Half-open intervals [1,5), [3,8), [10,12), [11,15). How many integer points lie in at least one of these intervals?
- Array [5, -5, 2, 3, -2, 7, 3]. How many contiguous subarrays have a sum that is 0, 5 or 10?
- Sorted positive array [1, 3, 4, 6, 9, 12]. How many index pairs i < j have a[i] a[j] >= 18?
- How many integers x with 1 <= x <= 64 have a binary representation (without leading zeros) that reads the same forwards and backwards?
- Problem: The suffix array of a string is its suffix start indices sorted by the suffix text. What is the value at position 2 (0-based) for…
- Problem: How many topological orders does the DAG with edges 0->2, 1->2, 2->3 on vertices 0..3 have? Run the brute-force code. python from…