Maximum Data Transfer Time
Updated
Problem statement
A server network is represented as a tree of g_nodes servers numbered from 1 to g_nodes. The network contains g_nodes - 1 edges, where the ith edge connects servers g_from[i] and g_to[i].
Transferring data across one edge takes 1 unit of time. Return the maximum time required to transfer data between any two servers in the network.
Function
getMaxTime(g_nodes: int, g_from: int[], g_to: int[]) → intExamples
Example 1
g_nodes = 3g_from = [1,2]g_to = [2,3]return = 2The longest transfer path is from server 1 to server 3. It crosses two edges, so the maximum transfer time is 2.
Constraints
1 ≤ g_nodes ≤ 5 * 10^41 ≤ g_from[i], g_to[i] ≤ g_nodes
More Microsoft Online Assessment questions
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
- Maximum Interactive Team SizeOA · Seen Nov 2026
- Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
- Minimum Cost K-Capable ModelsOA · Seen Nov 2026
- Find Available Meeting RoomsOA · Seen Oct 2026
- Maximum Sum of a K-StarOA · Seen Oct 2026
- Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Longest Transfer Time in a Server TreeRippling · OARippling 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
Microsoft interview experiences
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
- Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
- Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)