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?
- A. 8
- B. 13
- C. 9
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A set of symbols has frequencies [5, 9, 12, 13, 16, 45]. Huffman coding repeatedly merges the two smallest weights, and each merge costs…
- A circular route has gas stations with gas = [1, 2, 3, 4, 5, 2] and travel cost to the next station = [3, 4, 5, 1, 2, 3]. You start with…
- A garden of length 5 has taps at positions 0 to 5. Tap i waters the interval [i − ranges[i], i + ranges[i]] where ranges = [3, 4, 1, 1, 0…
- From the number 1432219 you must delete exactly 3 digits (the remaining digits keep their order). What is the smallest number you can…
- What is the minimum number of swaps of two (not necessarily adjacent) elements needed to sort the array [4, 3, 2, 1, 6, 5] into increasing…
- People weigh [3, 5, 3, 4, 2, 7, 1] kg. Each boat carries at most two people and at most 9 kg in total. What is the minimum number of boats…