Data Structures & AlgorithmsVery hardLeetCode-style · GATE CS

Tasks AAABBBCCD (each letter is a task, one unit of time each) run on a single CPU. Two identical tasks must be separated by at least n = 2 idle or other slots. What is the minimum total time needed to finish all tasks, given the cooldown rule?

  1. A. 8
  2. B. 13
  3. C. 9
  4. D. 6

Correct answer: C. 9

With m = 3 (A and B tied, nm = 2) and n = 2, the frame bound is (m − 1)(n + 1) + nm = 8, but there are 9 tasks, so the answer is max(9, 8) = 9. Forgetting the max gives 8, dropping the tie term gives 6, and adding n idle slots per gap to all tasks gives 13.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic