Company: Salesforce_12nov
Difficulty: medium
Problem Description A mountain trekking club has mapped its N base camps as a tree, where each camp is a node and each trail directly connecting two camps is an edge. A camp is called a "key team" if it lies at one end of any of the tree's longest trekking routes (diameters). For every camp in the network, determine whether it is a key team. Return a binary array where the Pth value is 1 if the Pth camp is a key team, and 0 otherwise. Note: The diameter of a tree is defined as the number of edges in the longest path of the tree. For example, consider a tree with nodes 1, 2, 3 and edges (1,2), (2,3). This tree has exactly one diameter, the path between nodes 1 and 3, of length 2. Its end-points are 1 and 3, so nodes 1 and 3 are key teams while node 2 is not. Complete the function isKeyTeam in the editor below. The function isKeyTeam has the following parameter(s): - tree_nodes : Total count of nodes present in the tree. - tree_from : One endpoint of each edge (the node the edge originat