FastPrepFastPrep
Problem Brief

Maximum Time Taken to Transfer Data

NEW GRADOA

A server network is represented as a tree of g_nodes servers indexed from 1 to g_nodes and g_nodes - 1 edges where the ith edges connect the servers g_from[i] and g_to[i]. The transfer time between any two connected servers is 1 unit.

Given the graph g, find the maximum time taken to transfer the data between any two servers in the system.

Function Description

Complete the function maximumTimeTakenToTransferData in the editor.

maximumTimeTakenToTransferData has the following parameters:

  1. 1. int g_nodes: the number of nodes
  2. 2. int[] g_from: an array of integers representing the start nodes
  3. 3. int[] g_to: an array of integers representing the end nodes

Returns

int: the maximum time taken to transfer data between any two servers

1Example 1

Input
g_nodes = 3, g_from = [1, 2], g_to = [2, 3]
Output
2
Explanation

The maximum time is required to transfer data from 1 to 3 that takes 2 units of time. Hence, the answer is 2.

public int maximumTimeTakenToTransferData(int g_nodes, int[] g_from, int[] g_to) {
  // write your code here
}
Input

g_nodes

3

g_from

[1, 2]

g_to

[2, 3]

Output

2

Sign in to submit your solution.