All practice tasks

Coding (Algo)

Measure Network Transfer Capacity

Maximum flow · Hard

A network planning tool estimates how much integral throughput can pass from one node to another. Directed links have independent capacities, and multiple links may connect the same endpoints. A locally attractive route can consume capacity that a better combination needs, so residual rerouting matters.

Return the maximum total integral flow from source to sink while respecting every link capacity and flow conservation at other nodes.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ n: integer, edges: [integer, integer, integer][], source: integer, sink: integer }

Fields

  • Nodes are indexes 0..n-1. An edge [u,v,capacity] is directed; parallel links add capacity and opposite-direction links are independent.
  • source and sink are distinct valid indexes. Capacities are non-negative integers; zero-capacity links and self-loops are permitted.

Output

Return value

  • Return one non-negative integer flow value, not a route or residual graph.
  • An unreachable sink returns zero. Self-loops cannot increase net source-to-sink flow.

Constraints

  • 2 <= n <= 80; 0 <= edges.length <= 1500; 0 <= capacity <= 1000000.
  • All endpoints are valid. Total capacity fits a safe JSON integer. Do not mutate input.

Examples

Example 1

{
  "edges": [
    [
      0,
      1,
      3
    ],
    [
      0,
      2,
      2
    ],
    [
      1,
      3,
      2
    ],
    [
      2,
      3,
      4
    ],
    [
      1,
      2,
      1
    ]
  ],
  "n": 4,
  "sink": 3,
  "source": 0
}

Returns

5

Example 2

{
  "edges": [
    [
      0,
      1,
      2
    ],
    [
      0,
      1,
      3
    ],
    [
      1,
      0,
      9
    ]
  ],
  "n": 2,
  "sink": 1,
  "source": 0
}

Returns

5

Required complexity

O(V * E^2) time for breadth-first augmenting paths and O(V^2 + E) space for a capacity matrix plus adjacency

What this task practices

Measure Network Transfer Capacity is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.