Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A list of 6 customers arrives at a bank counter with service times 4, 1, 3, 2, 6, 5 (in that arrival order). The counter serves them in shortest-job-first order (all present at time 0, non-preemptive). What is the average waiting time (time spent before service starts), as a whole number after truncation?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
Shortest-job-first minimises total waiting by serving short jobs first; each customer waits for the sum of the services before it. Using the arrival order instead gives a larger average.
More Coding Interview Problems questions
- Problem: A linked list of 10 nodes is traversed with Floyd's tortoise and hare: the slow pointer moves 1 step and the fast pointer moves 2…
- Problem: An LRU cache holds 3 entries. Keys are accessed in this order: 1, 2, 3, 1, 4, 2, 5, 1, 3, 4. A key is a hit if it is already…
- Problem: Tower of Hanoi with 6 disks, moving all disks from peg A to peg C using peg B as the spare (standard rules). How many moves does…
- Problem: Count the integers from 1 to 999 whose decimal digit sum is divisible by 7.
- Problem: Compute Euler's totient φ(n) summed over n = 1 to 30 (φ(n) counts integers in [1, n] coprime to n, with φ(1) = 1).
- Problem: How many positive divisors does 720 have?