Problem · Tree

Corporate Ladder

MediumBlackrockINTERNOA

A company wants to track change in their organization by knowing how many levels exist between any two employees. This number will help them know who is being promoted and who is not.

For example: If Susan reports to John and John reports to Amy. Then, there are 2 level between Susan and Amy.

Write a program that will count how many levels exist between any two names in a hierarchy of employees. The program must read a list of name pairs that represent an employee and their manager.

HINT: The two names to compare may be in different parts of the organizational tree and not have a direct managerial line.

Input:

The first line of input will be a pair of names to compare.

All subsequent lines will be employee/manager pairs. The company's complete hierarchy will be included so no incomplete trees will exist.

Examples
01 · Example 1
pairOfNamesToCompare = ["Susan", "Amy"]
employeePairs = [["Susan", "John"], ["John", "Amy"]]
return = 2
The number of levels between the pairs requested, including the top manager's level. In the example above, the Output should be 2. P.S. I am not 100% sure about the input of the example. If you find anythign wrong, pls feel free to lmk! Manyyy thanks in advance!! 😘
02 · Example 2
pairOfNamesToCompare = ["Scott", "David"]
employeePairs = [["Terry", "David"], ["Kyle", "David"], ["Ben", "Kyle"], ["Scott", "Jon"], ["Chris", "Scott"], ["Jon", "Kenny"], ["Kenny", "David"], ["David", "Mike"]]
return = 3
N/A for now
03 · Example 3
pairOfNamesToCompare = ["Ben", "Jon"]
employeePairs = [["Terry", "David"], ["Kyle", "David"], ["Ben", "Kyle"], ["Scott", "Jon"], ["Chris", "Scott"], ["Jon", "Kenny"], ["Kenny", "David"]]
return = 0
N/A for now
04 · Example 4
pairOfNamesToCompare = ["Christy", "Susan"]
employeePairs = [["Aimee", "Melissa"], ["Melissa", "Susan"], ["Stacy", "Corinne"], ["Gabrielle", "Melissa"], ["Corinne", "Melissa"], ["Christy", "Stacy"], ["Pat", "Christy"]]
return = 4
N/A for now
More Blackrock problems
drafts saved locally
public int countLevelsBetweenEmployees(String[] pairOfNamesToCompare, String[][] employeePairs) {
  // write your code here
}
pairOfNamesToCompare["Susan", "Amy"]
employeePairs[["Susan", "John"], ["John", "Amy"]]
expected2
sign in to submit