This is a verified interview question from Uber. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Minimum Travel Time with Mandatory Stops" covers key patterns like Other.
"At Uber, drivers must complete pickups and drop-offs in a specific order. The city is modeled as an undirected weighted graph: Nodes represent intersections. Edges represent roads with travel time weights. The driver: Starts at node 1 Must visit node x Then visit node y Finally reach node r_nodes Nodes may be revisited if necessary. Task Compute the minimum total travel time for: 1 → x → y → r_nodes Function Signature int minTotalTime( int r_nodes, vector<int> r_from, vector<int> r_to, vector<int> r_weight, int x, int y ); Example r_nodes = 5 r_from = [1, 2, 3, 4, 5, 1, 3] r_to = [2, 3, 4, 5, 1, 5] r_weight = [9, 11, 6, 1, 4, 10] x = 2 y = 4 Possible routes: 1. 1 -> 2 -> 3 -> 4 -> 5: Total time = 9 + 11 + 6 + 1 = 27 2. 1 -> 5 -> 4 -> 3 -> 2 -> 1 -> 5: Total time is incorrect logic. 3. Let's re-examine the correct logic from the first image which had a typo in the second route. The correct example routes from the image are: 1. 1 -> 2 -> 3 -> 5: Total time = 9 + 11 + 10 = 30 (This path seems to be a mistake in the image as it doesn't follow the 1 -> x -> y -> r_nodes sequence which is 1 -> 2 -> 4 -> 5) 2. 1 -> 2 -> 3 -> 4 -> 5: Total time = 9 + 11 + 6 + 1 = 27 The shortest route takes 27 time units. Note: Ride can visit any node multiple times if needed."
Join thousands of developers practicing for Uber.