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 levels 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.
Example 1:
Input: employeePairs = [['Susan', 'John'], ['John', 'Amy']], employee1 = "Susan", employee2 = "Amy"
Output: 2
Explanation:If Susan reports to John and John reports to Amy. Then, there are 2 levels between Susan and Amy.
Example 2:
Input: employeePairs = [['Scott', 'David'], ['Terry', 'David'], ['Kyle', 'David'], ['Ben', 'Kyle'], ['Scott', 'Jon'], ['Chris', 'Scott'], ['Jon', 'Kenny'], ['Kenny', 'David'], ['David', 'Mike']], employee1 = "Scott", employee2 = "David"
Output: 3
Explanation:To find the levels between Scott and David, we can trace the hierarchy as follows: Scott reports to Jon, Jon reports to Kenny, and Kenny reports to David. Therefore, there are 3 levels between Scott and David.
N/A

input:
output: