Data Structures & AlgorithmsVery hardTCS NQT Digital · Product Company SDE
Problem: Four processes arrive at times 0, 2, 4, 6 with burst times 6, 2, 8, 3. The scheduler is shortest-remaining-time-first (preemptive). What is the completion time of the process that arrives at time 4?
- A. 16
- B. 19
- C. 15
- D. 11
Correct answer: B. 19
SRTF: P1 runs 0-2, P2 (2 units) preempts it and finishes at 4, P1 finishes at 8, P4 runs 8-11, and P3 (arrival 4, burst 8) runs last to 19. FCFS order would finish P3 at 16, its turnaround time is 19 − 4 = 15, and 11 is P4's completion time.
More Coding Interview Problems questions
- Problem: In the grid of 0s and 1s below, count the number of 2×2 all-ones squares. 1110 1111 0111 1111
- Problem: A string s = "abacaba" is given. How many of its substrings are palindromes of odd length (counting index ranges, so repeated…
- Problem: A directed graph has 4 vertices (0–3) and arcs with weights: 0→1 (4), 1→2 (−3), 0→2 (2), 2→3 (1), 1→3 (5), 3→1 (−1). Start with…
- Array a = [4, 2, 6, 1, 5, 3, 3, 9, 2]. How many contiguous subarrays of length at least 3 have a sum divisible by 6?
- Array a = [3, 5, 8, 2, 7, 10, 4]. How many pairs of positions i < j have a[i] + a[j] equal to some value located strictly after position j?
- Sorted array b = [1, 2, 3, 4, 5, 7, 8, 9]. What is the largest product b[i] b[j] over index pairs with j - i >= 3?