Dsa
Trees
Medium
The Root of All Latency
In a distributed network (a tree), the latency between two nodes is the number of edges between them. You need to select one node to be the 'Master Hub'. The quality of the Master Hub is defined by the maximum latency to any other node in the network. Find the minimum possible maximum latency.
Input Format:
- Line 1: N, the number of nodes.
- Next N-1 lines: u v (an edge).
Output Format:
- An integer representing the minimum possible 'max latency'.
Example:
Input:
4
1 2
2 3
3 4
Output:
2
(If node 2 or 3 is the hub, the max distance to any leaf is 2.)
Key concepts
tree rerootingdynamic programming
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now