Highest-capacity route
A free hard coding practice problem from networking. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Hard
- Type
- Function
- Topic
- Networking
- Languages
- JavaScript, TypeScript or Python
Problem
Trucks carry freight between n depots numbered 0…n-1 over two-way roads [a, b, capacity] (integer capacity ≥ 1, the most a truck may carry on that road). A route's capacity is the smallest capacity among its roads. Return the largest capacity of any route from src to dst (src ≠ dst), or -1 when they aren't connected. Up to 20,000 depots and 60,000 roads.
Function signature
// JavaScript
function widestRoute(n, roads, src, dst)
// TypeScript
function widestRoute(n: any, roads: any, src: any, dst: any): any
// Python
def widest_route(n, roads, src, dst):Examples
widestRoute(4, [[0,1,5],[1,3,2],[0,2,3],[2,3,4]], 0, 3)→3widestRoute(3, [[0,1,10]], 0, 2)→-1
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.