All practice tasks

Coding (Algo)

Minimize the Largest Route Cost

Priority queue · Medium

A delivery route is limited by its most expensive individual connection rather than by the total cost. A route with more edges can be preferable if each connection is cheaper. The routing tool must minimize that maximum edge and report its value.

Return the smallest achievable maximum edge weight along a directed source-to-target route and null when no route exists.

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, target: integer }

Fields

  • n is the node count and edges contains directed [from,to,weight] triples. Parallel edges are distinct input entries; self-loops are allowed.
  • All weights are non-negative integers unless the task explicitly requires positive weights.
  • source is the starting node. source = -1 means no starting node and yields no reachable nodes.
  • target is the destination node. target = -1 means no destination and yields no route.

Output

Return value

  • Return the minimum bottleneck cost, not the total route weight. A valid empty route from a node to itself has bottleneck zero.
  • Missing or unreachable endpoints return null.

Constraints

  • 0 <= n <= 50000; 0 <= edges.length <= 200000; endpoints are valid node labels; 0 <= weight <= 1000000.
  • source and target, when used, are either -1 or valid node labels. All distance and slack results fit a safe JSON integer.

Examples

Example 1

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

Returns

4

Example 2

{
  "edges": [],
  "n": 1,
  "source": 0,
  "target": 0
}

Returns

0

Required complexity

O(n + m log(m + 1)) time and O(n + m) auxiliary space

What this task practices

Minimize the Largest Route Cost 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 medium 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.