FastPrepTop-Down Employee Reporting Forest
Problems/Top-Down Employee Reporting Forest

Top-Down Employee Reporting Forest

Okta logoOkta● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report supplies employee-to-manager pairs and asks for top-down reporting output. Lexicographic sibling and root order plus depth encoding make the forest traversal deterministic; the judged core task matches at about 91%.

Each row of employeeManager is [employee, manager]. An empty manager string marks a root. The rows describe a valid reporting forest: every employee appears once, every non-empty manager is also an employee, and there are no cycles.

Return the forest in deterministic top-down preorder. Visit roots in lexicographic order and visit each manager's direct reports in lexicographic order. Encode each visited employee as depth:name, where roots have depth 0.

Function

topDownReportingForest(employeeManager: String[][]) → String[]

Examples

Example 1

employeeManager = [["alice",""],["bob","alice"],["cara","alice"],["dan","bob"]]return = ["0:alice","1:bob","2:dan","1:cara"]

A preorder walk visits Alice, Bob's subtree, and then Cara.

Example 2

employeeManager = [["zane",""],["amy",""],["lee","zane"]]return = ["0:amy","0:zane","1:lee"]

The two roots are ordered lexicographically before their subtrees are traversed.

Example 3

employeeManager = [["solo",""]]return = ["0:solo"]

A one-person organization is a one-node forest.

Constraints

  • 1 <= employeeManager.length <= 100000.
  • Every row has exactly two strings.
  • Employee names are unique non-empty lowercase identifiers.
  • The manager is either empty or names another employee.
  • The relationships form a forest.

More Okta problems

  • Simple Bank OperationsONSITE INTERVIEW · Seen Oct 2026
  • Randomized Collection with Duplicate ValuesONSITE INTERVIEW · Seen Sep 2026
  • Role-Based Network Access ControlPHONE SCREEN · Seen Aug 2026
All Okta interview questionsSee Okta hiring insights
Saved
class Solution {
    public String[] topDownReportingForest(String[][] employeeManager) {
        // Write your solution here.
    }
}
Checking account…