As reported: Microsoft L62 SWE online assessment on HackerRank (Sep 2025), two questions; the second (advanced level) combined graphs and dynamic programming.
A country has g_nodes cities numbered 1 … g_nodes, joined by g_edges bidirectional roads. Road i connects g_from[i] and g_to[i] and needs g_weight[i] units of fuel to drive.
A vehicle has unlimited fuel capacity. In city i, one unit of fuel costs arr[i−1] (the array is 0-indexed), and any non-negative amount can be bought in any city the vehicle passes through. The vehicle starts in city A with an empty tank.
Return the minimum total cost of the fuel needed to travel from city A to city B, or -1 if B cannot be reached.
Example 1
g_nodes = 5
g_from = [3,5,1,4,3]
g_to = [5,1,4,2,2]
g_weight = [1,1,1,9,20]
arr = [9,11,3,2,10], A = 3, B = 2
-> 27
Drive 3 → 5 → 1 → 4 → 2: buy 3 units in city 3 (price 3) for the first three roads, then 9 units in city 4 (price 2) for the last one: 9 + 18 = 27. The direct road 3 → 2 would cost 20 × 3 = 60.
Example 2
g_nodes = 4, g_from = [1,2,3,2], g_to = [2,3,4,4], g_weight = [2,3,4,10]
arr = [5,1,8,8], A = 1, B = 4
-> 17
Buy 2 units in city 1 (10), then in city 2 buy 7 units at price 1 for 2 → 3 → 4 (7).
Example 3
g_nodes = 3, g_from = [1], g_to = [2], g_weight = [4], arr = [3,3,3], A = 1, B = 3 -> -1
Constraints: 1 ≤ g_nodes ≤ 200; 0 ≤ g_edges ≤ 1000; 1 ≤ g_weight[i] ≤ 1000; 1 ≤ arr[i] ≤ 10^6; 1 ≤ A, B ≤ g_nodes. There may be several roads between the same two cities. The answer can exceed 32 bits — return a 64-bit integer.
Code runner format: one JSON value per line: g_nodes, g_from, g_to, g_weight, arr, A, B. Implement minFuelCost(gNodes, gFrom, gTo, gWeight, arr, a, b); the harness prints the result.