FastPrepFastPrep
Problem Brief

Corporate Ladder

INTERNOA

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.

1Example 1

Input
pairOfNamesToCompare = ["Susan", "Amy"], employeePairs = [["Susan", "John"], ["John", "Amy"]]
Output
2
Explanation
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!! 😘

2Example 2

Input
pairOfNamesToCompare = ["Scott", "David"], employeePairs = [["Terry", "David"], ["Kyle", "David"], ["Ben", "Kyle"], ["Scott", "Jon"], ["Chris", "Scott"], ["Jon", "Kenny"], ["Kenny", "David"], ["David", "Mike"]]
Output
3
Explanation
N/A for now

3Example 3

Input
pairOfNamesToCompare = ["Ben", "Jon"], employeePairs = [["Terry", "David"], ["Kyle", "David"], ["Ben", "Kyle"], ["Scott", "Jon"], ["Chris", "Scott"], ["Jon", "Kenny"], ["Kenny", "David"]]
Output
0
Explanation
N/A for now

4Example 4

Input
pairOfNamesToCompare = ["Christy", "Susan"], employeePairs = [["Aimee", "Melissa"], ["Melissa", "Susan"], ["Stacy", "Corinne"], ["Gabrielle", "Melissa"], ["Corinne", "Melissa"], ["Christy", "Stacy"], ["Pat", "Christy"]]
Output
4
Explanation
N/A for now
public int countLevelsBetweenEmployees(String[] pairOfNamesToCompare, String[][] employeePairs) {
  // write your code here
}
Input

pairOfNamesToCompare

["Susan", "Amy"]

employeePairs

[["Susan", "John"], ["John", "Amy"]]

Output

2

Sign in to submit your solution.