Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Cars pass a toll booth at times 2, 5, 6, 10, 11, 15 (minutes). A car may pass only if at least 3 minutes have elapsed since the previous car that passed. How many cars pass?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Greedy acceptance in time order: car at 2 passes, car at 5 passes (gap 3), car at 6 is too soon, car at 10 passes, car at 11 is too soon, and car at 15 passes, giving four cars.
More Coding Interview Problems questions
- Problem: A sorted list of distinct integers is 3, 8, 12, 17, 21, 26, 30. How many pairs (i < j) have a[j] − a[i] exactly equal to 9?
- Problem: The value of 3^(3^3) mod 7 is what?
- Problem: A path graph has vertices 1–6 with edges between consecutive vertices. How many pairs of vertices are at distance exactly 2?
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→4, 4→2, 1→5. Starting from 1, how many distinct vertices are reachable…
- Problem: In the array [9, 2, 6, 4, 7, 1], what is the number of elements that are smaller than every element to their left (strict left…
- Problem: The number 2^10 − 1 has how many distinct prime factors?