As reported: ServiceNow Software Engineer (IC2) loop in Hyderabad, round 1 (DSA), Feb 2026: a directed graph of oases where each edge has a base weight
w, and afterksteps already taken, taking an edge of weightwcostsw + k; find the minimum cost fromStoT. Also in that round: URL autocomplete with a trie.
There are n oases 0…n−1 and directed edges [u, v, w]. A route from source to target takes edges one after another; the i-th edge taken (counting from 1) costs w + (i − 1). Return the minimum total cost of a route, 0 if source == target, or -1 if target cannot be reached.
Example
n = 4, edges = [[0,1,1],[1,3,1],[0,2,1],[2,3,1],[0,3,4]], 0 -> 3 -> 3 (0→1 costs 1, 1→3 costs 1+1)
n = 3, edges = [[0,1,5]], 0 -> 2 -> -1
n = 5, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,1],[0,4,9]], 0 -> 4 -> 9 (the 4-step path costs 4 + 0+1+2+3 = 10)
Constraints: 1 ≤ n ≤ 100; 0 ≤ edges.length ≤ 2000; 1 ≤ w ≤ 10^6; u ≠ v; parallel edges may exist.
Code runner format: line 1 n, line 2 edges, line 3 source, line 4 target. Implement minCost(n, edges, source, target); the harness prints the cost.
Clarifications
kcounts edges already taken, so the first edge costs exactlyw. A route that usesLedges pays0 + 1 + … + (L − 1) = L(L − 1)/2in penalties on top of its weights.