Office Employee Hierarchy
Updated
Problem statement
An office has a head and employees. Every person has a different integer ID. Everyone except the head reports to exactly one manager, who is also in the office. At the start, the office holds only the head, whose ID is headId.
You are given a list of operations. Operation operations[i] uses the numbers in args[i]:
"add"with[id, managerId]: a new employeeidjoins and reports tomanagerId. The IDidis not in the office at that moment, andmanagerIdis."changeManager"with[id, managerId]: employeeidnow reports tomanagerId. The people who report toidkeep reporting toid, so they move along. Hereidis in the office and is not the head, andmanagerIdis in the office and is neitheridnor anyone belowid."delete"with[id]: employeeidleaves. The people who reported directly toidnow report to the manageridhad. Hereidis in the office and is not the head."print"with[]: record the current hierarchy as a string.
The string for a person is their ID. If they have direct reports, it is followed by the strings of those reports in parentheses, separated by commas, in increasing ID order. A person with no reports has no parentheses. For example, "1(2(4),3)" means that 2 and 3 report to 1 and 4 reports to 2. The hierarchy string is the string of the head.
Return the strings recorded by the "print" operations, in order.
Function
manageOffice(headId: int, operations: String[], args: int[][]) → List<String>Examples
Example 1
headId = 1operations = ["add","add","add","print","changeManager","print","delete","print"]args = [[2,1],[3,1],[4,2],[],[4,3],[],[3],[]]return = ["1(2(4),3)","1(2,3(4))","1(2,4)"]After the three adds, 2 and 3 report to the head 1, and 4 reports to 2. The first print is "1(2(4),3)".
Then 4 moves to manager 3, so the second print is "1(2,3(4))". Deleting 3 moves its report 4 up to 3's manager, the head 1. The last print is "1(2,4)".
Example 2
headId = 10operations = ["add","add","add","print"]args = [[11,10],[9,10],[2,9],[]]return = ["10(9(2),11)"]11 and 9 report to 10, and 2 reports to 9. Reports are listed by increasing ID as numbers, so 9 comes before 11. The print is "10(9(2),11)".
Example 3
headId = 5operations = ["add","add","add","delete","print"]args = [[7,5],[8,7],[6,7],[7],[]]return = ["5(6,8)"]7 reports to 5, and 8 and 6 report to 7. When 7 is deleted, 8 and 6 move up to 7's manager, 5. The print is "5(6,8)".
Constraints
1 <= operations.length <= 1000andargs.length == operations.length1 <= headId, args[i][j] <= 10000args[i].lengthis 2 for"add"and"changeManager", 1 for"delete"and 0 for"print".- Every operation is valid as described above, and
operationscontains at least one"print". - The office never has more than 200 people, the head included.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Workspace File System With Folders and TablesClay · PHONE SCREEN
- In-Memory File System With Directory SizesCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
Bloomberg LP interview experiences
- Bloomberg SWE Phone Screen and Onsite: 1 Experience
- Bloomberg SWE Phone Screens with Two Teams: 1 Experience
- Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
- Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
- Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
- Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience