Data Structures & AlgorithmsVery hardGATE CS
An undirected weighted graph on vertices 0-5 has edges (u, v, w): (0,1,2), (0,2,2), (1,3,3), (2,3,3), (1,4,5), (2,4,5), (3,5,1), (4,5,1), (0,3,5), (3,4,2), (2,5,7). How many distinct shortest paths exist from vertex 0 to vertex 5?
- A. 5
- B. 3
- C. 4
- D. 2
Correct answer: B. 3
Dijkstra with path counting gives shortest distance 6 and 3 shortest paths. Routes of equal length through the direct edge (0,3) or the (3,4) edge must also be counted.
More Coding Interview Problems questions
- Problem: A delivery app logs the parcel weights of a day in an array. Return the indices of the two parcels whose weights add up exactly…
- Problem: Given an unsorted array of n ≤ 10⁵ integers and a target, report whether two different positions hold values summing to the…
- Problem: A stock tracker gets daily prices and must report the best profit from one buy followed by one later sell (0 if no profit is…
- Problem: Find the largest sum of a non-empty contiguous block of an array (values may be negative). python def best(a): cur = ans = a[0]…
- Problem: Rotate an array to the right by k steps in place, using O(1) extra space. Example: [1, 2, 3, 4, 5], k = 2 → [4, 5, 1, 2, 3]…
- Problem: Every number in a list of sensor IDs appears twice except one. Find the lonely ID in O(n) time and O(1) space. python def…