Corporate Ladder
Updated
Problem statement
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.
Function
countLevelsBetweenEmployees(pairOfNamesToCompare: String[], employeePairs: String[][]) → intExamples
Example 1
pairOfNamesToCompare = ["Susan", "Amy"]employeePairs = [["Susan", "John"], ["John", "Amy"]]return = 2The 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!! 😘
Example 2
pairOfNamesToCompare = ["Scott", "David"]employeePairs = [["Terry", "David"], ["Kyle", "David"], ["Ben", "Kyle"], ["Scott", "Jon"], ["Chris", "Scott"], ["Jon", "Kenny"], ["Kenny", "David"], ["David", "Mike"]]return = 3N/A for now
Example 3
pairOfNamesToCompare = ["Ben", "Jon"]employeePairs = [["Terry", "David"], ["Kyle", "David"], ["Ben", "Kyle"], ["Scott", "Jon"], ["Chris", "Scott"], ["Jon", "Kenny"], ["Kenny", "David"]]return = 0N/A for now
Example 4
pairOfNamesToCompare = ["Christy", "Susan"]employeePairs = [["Aimee", "Melissa"], ["Melissa", "Susan"], ["Stacy", "Corinne"], ["Gabrielle", "Melissa"], ["Corinne", "Melissa"], ["Christy", "Stacy"], ["Pat", "Christy"]]return = 4N/A for now
More BlackRock interview questions
- Find Minimum TimeOA · Seen Nov 2026
- Count LevelsOA · Seen Sep 2026
- Valid ParenthesesOA · Seen Sep 2026
- Lowest Common Ancestor in a Parent TreeOA · Seen Sep 2026
- Road Trip (Analyst Program :POA · Seen Aug 2026
- Set IntersectionOA · Seen Aug 2026
- Process SchedulingPHONE SCREEN · Seen Mar 2026
- John Venn (Analyst Program :)OA · Seen Sep 2024
- Happy NumberOA · Seen Jul 2024
Similar questions at other companies
- Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Vertical Order Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
- Decrypt a String from Binary Tree ColumnsBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Binary Tree Vertical Order with Stable TiesMeta · ONSITE INTERVIEWMeta interview questions
- Everyone Under a ManagerAdobe · PHONE SCREENAdobe interview questions
- Team Cost Under a ManagerRippling · PHONE SCREENRippling interview questions
- Top View of a Binary TreeInMobi · ONSITE INTERVIEWInMobi interview questions
- Path Between Two Binary-Tree NodesSnowflake · PHONE SCREENSnowflake interview questions