As reported: eBay SSE, in-person drive, DSA round (2026): cities are nodes; going from A to B costs X and from B to A costs Y. Given the edge list with costs, a start city and an end city, find the round-trip cost.
There are n cities 0 … n−1. Each road is given once as [u, v, there, back]: travelling from u to v costs there, and from v to u costs back. Given a start city a and a destination b, return the minimum total cost to travel from a to b and then back to a (each leg may pass through other cities). Return -1 if either leg is impossible.
Example 1
n = 3, roads = [[0,1,5,2],[1,2,4,9],[0,2,20,1]], a = 0, b = 2 -> 10
Go 0 → 1 → 2 for 5 + 4 = 9, come back 2 → 0 directly for 1.
Example 2
n = 2, roads = [[0,1,3,7]], a = 0, b = 1 -> 10
Constraints: 1 ≤ n ≤ 2·10^4; 0 ≤ roads.length ≤ 5·10^4; 0 ≤ there, back ≤ 10^6; u ≠ v; there may be several roads between the same pair of cities. The answer can exceed 32-bit range.
Code runner format: one JSON value per line: n, roads, a, b. Implement roundTripCost(n, roads, a, b); the harness prints the cost.
Clarifications
- If
a == bthe answer is0. - The return trip may use different roads from the outbound trip.