Code Room
CodingHardcod-g697
Subject Min cost flowLevel Senior–Staff~45 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

A directed network on n nodes (0..n-1) has edges [u, v, cap, cost] meaning a pipe from u to v with the given capacity and a per-unit cost. Send the MAXIMUM possible flow from s to t, and among all maximum-flow solutions pick one of minimum total cost. Return [max_flow_value, min_total_cost]. All costs are non-negative. Constraints: 1 <= n <= 200; 0 <= cap, cost <= 1000.

Implement
min_cost_max_flow(n: int, edges: list[list[int]], s: int, t: int) → list[int]
Examples
in[4,[[0,1,3,1],[0,2,2,2],[1,3,2,1],[2,3,3,1],[1,2,1,1]],0,3]out[5,13]
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.