Lowest-Capacity Link Usable on Any Route Between Two Hubs

Last updated: November 29, 2026

Quick Overview

A network of n hubs has undirected links with capacities. A route from src to dst may revisit hubs and links. The score of a route is the smallest capacity on it. Return the minimum possible score among all routes from src to dst, or -1 if dst is unreachable.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


A network of n hubs has undirected links with capacities. A route from src to dst may revisit hubs and links. The score of a route is the smallest capacity on it. Return the minimum possible score among all routes from src to dst, or -1 if dst is unreachable.

This online assessment question looks like a shortest path problem but is not: since routes may revisit links, any link in the connected component is usable. The interviewer checks whether you spot that and reduce it to union-find with a per-component minimum.

What the Interviewer Expects
  • Notices that revisiting allows any link in the component
  • Reduces the problem to a component-wide minimum
  • Tracks the minimum capacity at each root during unions
  • Returns -1 when src and dst are in different components
  • Avoids Dijkstra-style overkill
Key Topics to Cover
Union-Find
Component Aggregates
Graphs
Problem Reduction
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if routes must be simple paths with no repeated hubs?
  • Answer many (src, dst) queries efficiently.
  • Now maximize the minimum capacity instead. What changes?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: n, list of (a, b, capacity), and src, dst.
  • Routes may repeat hubs and links.
  • Output: smallest achievable route score, or -1....
High-Level Design

If src and dst are connected, any link anywhere in their component can be reached from src, walked across, and left back toward dst, so the best score is simply the smallest capacity in the component....


Submit Your Answer
Markdown supported