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?

  1. A. 6
  2. B. 9
  3. C. 18
  4. 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

Exams that ask this topic