Problem · Hash Table
Worker Management, Part 3: Promotions and Salary
Learn this problemProblem statement
Continue the worker management system from Parts 1 and 2. Existing operations keep their behavior.
Promotions
["PROMOTE", worker_id, new_position, new_compensation, start_timestamp]: register a pending promotion. Returnsuccess, orinvalid_requestif the worker is missing or already has an unapplied promotion.- The promotion becomes active when the worker first enters the office at a timestamp greater than or equal to
start_timestamp. A session that begins earlier keeps the previous position and compensation. TOP_N_WORKERSconsiders only each worker's current position.GETcontinues to sum completed time across every past and current position.
Salary
["CALC_SALARY", worker_id, start_timestamp, end_timestamp]: return the salary earned during the half-open interval[start_timestamp, end_timestamp).- Only completed office sessions are paid. For each session, multiply the length of its intersection with the requested interval by the compensation active for that session.
- Return an empty string for a missing worker.
Function
workerManagementLevel3(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD_WORKER","John","Middle Developer","200"],["REGISTER","John","100"],["REGISTER","John","125"],["PROMOTE","John","Senior Developer","500","200"],["REGISTER","John","150"],["PROMOTE","John","Senior Developer","350","250"],["REGISTER","John","300"],["REGISTER","John","325"],["CALC_SALARY","John","0","500"],["TOP_N_WORKERS","3","Senior Developer"],["REGISTER","John","400"],["GET","John"],["TOP_N_WORKERS","10","Senior Developer"],["TOP_N_WORKERS","10","Middle Developer"],["CALC_SALARY","John","110","350"]]return = ["true","registered","registered","success","registered","invalid_request","registered","registered","35000","John(0)","registered","250","John(75)","","45500"]The session beginning at 150 keeps the old compensation because it starts before 200. The promotion applies when John next enters at 325. Salary over [110,350) is 15*200 + 150*200 + 25*500 = 45500.
More Anthropic problems
- Banking System, Part 1: Accounts and TransfersOA · Seen Jul 2026
- Banking System, Part 2: Top SpendersOA · Seen Jul 2026
- Banking System, Part 3: Scheduled PaymentsOA · Seen Jul 2026
- Banking System, Part 4: Merging and Balance HistoryOA · Seen Jul 2026
- Convert Stack Samples to Trace EventsPHONE SCREEN · Seen Jul 2026
- Cloud Storage SystemOA · Seen Jun 2026
- Repair the Bootloader ProgramONSITE INTERVIEW · Seen Jun 2026
- Normalize a DNS Domain NameOA · Seen May 2026