FastPrepInsert an Employee into an Organization Hierarchy
Problems/Insert an Employee into an Organization Hierarchy

Insert an Employee into an Organization Hierarchy

Waymo logoWaymo● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report keeps an organization-insertion task, the employee score rule, a limit on direct reports, a breadth-first fallback, and a follow-up to speed it up with a reverse map. It leaves out the hierarchy encoding, the sibling order, the form of the returned result, and the limits. Our version below supplies those details with fixed rules.

An organization is a rooted tree encoded by strings employeeId|managerId. Exactly one employee is the root and uses manager ID NONE. The order of rows defines the order among siblings.

An employee's score is 1 + number of direct reports. Insert newEmployee into the subtree rooted at requestedManager:

  1. If the requested manager has fewer than k direct reports, attach the new employee there.
  2. Otherwise, search the requested manager's descendants in breadth-first order. Within a level, visit direct reports in their row order.
  3. Attach the new employee to the first visited employee with fewer than k direct reports.

Return the complete updated organization as strings employeeId|managerId|score, sorted by employee ID in ascending lexicographic order.

Function

insertEmployee(organization: String[], requestedManager: String, newEmployee: String, k: int) → String[]

Examples

Example 1

organization = ["ceo|NONE","a|ceo","b|ceo","c|a"]requestedManager = "ceo"newEmployee = "d"k = 2return = ["a|ceo|3","b|ceo|1","c|a|1","ceo|NONE|3","d|a|1"]

ceo already has two direct reports. Breadth-first search visits a before b; a has one open position, so d is attached there. The scores of a and the new employee are 3 and 1.

Example 2

organization = ["root|NONE","east|root","leaf|east"]requestedManager = "root"newEmployee = "rover"k = 1return = ["east|root|2","leaf|east|2","root|NONE|2","rover|leaf|1"]

Both root and east are full. The first available employee in breadth-first order is leaf, so it becomes the new employee's manager.

Constraints

  • 1 <= organization.length <= 200000.
  • 1 <= k <= 100000.
  • Every employee ID is unique, nonempty, case-sensitive, and contains only English letters, digits, underscores, or hyphens.
  • newEmployee is not already present, and no employee ID equals NONE.
  • requestedManager identifies an existing employee.
  • The input describes one valid rooted tree, and every employee initially has at most k direct reports.

More Waymo Phone Screen questions

  • Shortest Travel Time in a Grid with Traffic LightsPHONE SCREEN · Seen Nov 2026
  • Fixed-Order Task Run Time With CooldownPHONE SCREEN · Seen Oct 2026
  • Reorderable Task Scheduler With CooldownPHONE SCREEN · Seen Oct 2026
  • Island Area and Water BoundaryPHONE SCREEN · Seen Sep 2026
  • Vehicle Maintenance Event ReadinessPHONE SCREEN · Seen Sep 2026
  • Obstacle-Aware Return to OriginPHONE SCREEN · Seen Sep 2026
  • Shortest Paths to Multiple TargetsPHONE SCREEN · Seen Sep 2026
  • Deterministic Depth-First Graph TraversalPHONE SCREEN · Seen Sep 2026
  • Shortest Distance from All BuildingsPHONE SCREEN · Seen Sep 2026
  • Fixed-Range Frequency CountPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Group AnagramsEPAM · PHONE SCREENEPAM interview questions
  • Flat Records to a Hierarchical TreeAddepar · PHONE SCREEN
  • Diff Two Filesystem Hash TreesCursor · PHONE SCREENCursor interview questions

Waymo interview experiences

  • Waymo New Grad MLE Phone Screen: Traffic Lights: 1 Experience
All Waymo interview questionsSee Waymo hiring insights
Saved
class Solution {
    public String[] insertEmployee(String[] organization, String requestedManager, String newEmployee, int k) {
        // write your code here
    }
}
Checking account…