Problem · Hash Table

Worker Management, Part 3: Promotions and Salary

Learn this problem
HardAnthropicOA

Problem 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. Return success, or invalid_request if 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_WORKERS considers only each worker's current position. GET continues 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

drafts saved locally
public String[] workerManagementLevel3(String[][] operations) {
  // write your code here
}
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"]]
expected["true", "registered", "registered", "success", "registered", "invalid_request", "registered", "registered", "35000", "John(0)", "registered", "250", "John(75)", "", "45500"]
checking account