FastPrepFastPrep
Problem Brief

Maximum Time Required 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 maximumTimeRequiredToTransferData in the editor.

maximumTimeRequiredToTransferData has the following parameters:

  1. int g_nodes: the number of servers
  2. int[] g_from: an array of integers representing the starting server of each edge
  3. int[] g_to: an array of integers representing the ending server of each edge

Returns

int: the maximum time required 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 required to transfer data from 1 to 3 that takes 2 units of time. Hence, the answer is 2.

2Example 2

Input
g_nodes = 5, g_from = [1, 1, 1, 5], g_to = [5, 3, 2, 4]
Output
3
Explanation
:)

3Example 3

Input
g_nodes = 7, g_from = [4, 4, 2, 1, 2], g_to = [2, 7, 5, 6, 3]
Output
4
Explanation
Then sample output in the source is indeed 4..it's just been cut out in the ss..
public int maximumTimeRequiredToTransferData(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.