Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE
Problem: Buses run fixed routes; from a stop, the number of distinct routes is what matters. Given the four routes [1,2,7], [3,6,7], [2,5], [5,8] (each a list of stops), what is the minimum number of routes needed to go from stop 1 to stop 8 by changing buses only at shared stops?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Treat routes as nodes and connect routes that share a stop; BFS over routes gives the fewest buses. Counting stops along the way instead of buses is a different measure.
More Coding Interview Problems questions
- Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it…
- Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).
- Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the…
- Problem: How many trailing zeros does 1000! have in base 10?
- Problem: The string "BANANA" has how many distinct arrangements of its letters (letters are identical when they match)?
- Problem: For the word-count test: how many distinct strings can be formed by rearranging "AABBCCD" so that no two identical letters are…