Company: Salesforce
Difficulty: medium
Key Salesforce Teams In a Salesforce organizational hierarchy, the structure is represented as a tree with tree_nodes nodes, each node corresponding to a team. The teams are numbered from 1 to tree_nodes . A communication path between two teams is the unique simple path connecting them in the tree, and its length is the number of edges on it. The diameter of the tree is the length of the longest such path. There may be several different paths whose length equals the diameter. A team is called a key team if it is an endpoint of at least one of the longest communication paths (diameters) within the hierarchy. For every team in the hierarchy, determine whether it is a key team. Return a binary array answer of size tree_nodes , where answer[i] is 1 if node i (1-indexed) is a key team, and 0 otherwise. If the hierarchy contains a single team, the longest communication path has length 0 and that single team is its endpoint, so the answer is [1] . Function Description Complete the function is