Longest Transfer Time in a Server Tree
Updated
Problem statement
A company runs serverCount servers numbered from 1 to serverCount. They are joined by serverCount - 1 two-way links, where links[i] = [a, b] connects server a and server b. Every server can reach every other server, so the network is a tree: there is exactly one route between any two servers.
Sending data across one link takes 1 unit of time, so sending data from one server to another takes as many units as there are links on the route between them.
Return the longest time needed to send data between any two servers. If there is only one server, return 0.
Function
longestTransferTime(serverCount: int, links: int[][]) → intExamples
Example 1
serverCount = 6links = [[1,2],[1,3],[3,4],[3,5],[5,6]]return = 4The longest route is 2 → 1 → 3 → 5 → 6. It uses 4 links, so it takes 4 units of time. No other pair of servers is farther apart; for example, 4 → 3 → 5 → 6 uses only 3 links.
Example 2
serverCount = 7links = [[4,1],[4,2],[2,3],[4,5],[5,6],[6,7]]return = 5The longest route is 3 → 2 → 4 → 5 → 6 → 7, which uses 5 links. Server 1 is not on it: the farthest server from server 1 is server 7, only 4 links away.
Example 3
serverCount = 1links = []return = 0There is only one server and no link, so the longest transfer time is 0.
Constraints
1 <= serverCount <= 5000links.length == serverCount - 1links[i].length == 21 <= links[i][0], links[i][1] <= serverCountlinks[i][0] != links[i][1], and together the links connect all servers (so there is no repeated link and no cycle).
More Rippling Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- Cyber Beacon DetectionOA · Seen Aug 2026
Similar questions at other companies
- Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions
- Special Diameter EndpointsAgoda · OAAgoda interview questions
- Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
- All Nodes Distance K in a Binary TreeAmazon · PHONE SCREEN
- Tree DiameterQualcomm · PHONE SCREENQualcomm interview questions
- Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
- Part 1: The Narrowest KeyScale AI · OAScale AI interview questions
- Tree Pythagorean TriplesIBM · OAIBM interview questions
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
- Count Islands with DFS and BFSVisa · OAVisa interview questions