Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A process list is [3, 7, 2, 9] with priorities; the CPU always runs the largest value next and runs it for its full value, then removes it. Running in this way, what is the completion time of the process with value 2 (the time counted as the total units run before it finishes)?
- A. 19
- B. 12
- C. 21
- D. 2
Correct answer: C. 21
Largest-first order is 9, 7, 3, 2, so process 2 finishes at 9 + 7 + 3 + 2 = 21. Its start time is 19, running in listed order would finish it at 3 + 7 + 2 = 12, and shortest-first would finish it at 2.
More Coding Interview Problems questions
- Problem: How many subarrays of [2, 4, 6, 1, 3, 5] have all elements even or all elements odd?
- Problem: The number 9 is written in base 3 as 100. How many numbers from 1 to 100 have a base-3 representation with no digit 2?
- Problem: On a line of cells 0–9, a token starts at cell 0. Each second it moves right by 2 if the cell is even, and left by 1 if the cell…
- Problem: Count the pairs (i, j) with 1 ≤ i < j ≤ 12 for which the number i·j is a perfect square.
- Problem: The array [4, 9, 2, 7, 5, 6] is processed by insertion sort (standard insertion into the sorted prefix, shifting larger elements…
- Problem: The matrix [[1,2,3],[4,5,6],[7,8,9]] is traversed by rows, but with each row read alternately left-to-right and right-to-left…