This is a verified interview question from Salesforce. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Key Salesforce Teams" covers key patterns like Graphs.
"In a Salesforce organizational hierarchy, the structure is represented as a tree with n nodes, each corresponding to a team. A team is called 'key team' if it is an endpoint of any of the longest communication paths (diameters) within the hierarchy. For all the teams in the hierarchy, determine if they are key teams or not. Thus, return a binary array, where the ith value of the array is 1, in case the ith node is a key team. Else, the ith value of the array will be 0. Note: The diameter of a tree is defined as the number of edges in the longest path of the tree. For example, consider the tree given below: We can see that this tree has only one diameter, which is the unique path between nodes 1 and 3. The length of the diameter is 2. The end-points of the diameter are 1 and 3. Hence, nodes 1 and 3 are considered special, while node 2 is not considered a special node of the tree. "
Join thousands of developers practicing for Salesforce.