Code RoomMaximum flow
HardPrep Room Coding #1031

Maximum flow

CodingAlgorithms & data structuresSenior–Staff~35 min

Given a directed graph with n nodes (0..n-1) and a list of edges [u, v, c] meaning a directed pipe from u to v with non-negative integer capacity c (parallel edges should be summed), compute the maximum flow from source s to sink t. Return the max flow value (0 if t is unreachable). Assume 1 <= n <= 200 and capacities up to a few thousand; an augmenting-path method (Edmonds-Karp) must finish well under 5s.

Implement
max_flow(n: int, edges: list[list[int]], s: int, t: int) → int
Examples
in[4,[[0,1,3],[0,2,2],[1,2,1],[1,3,2],[2,3,3]],0,3]out5
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[4,[[0,1,3],[0,2,2],[1,2,1],[1,3,2],[2,3,3]],0,3]5not run yetsample