FastPrepWorker Management, Part 3: Promotions and Salary

Worker Management, Part 3: Promotions and Salary

Ramp logoRamp● HardNEW GRADINTERNOA
Learn

Problem statement

The source assessment is a cumulative four-level worker-hours register for contract workers at a facility. Each level includes every operation from the earlier levels. This page implements Levels 1 through 3 and returns one string result for every query in input order.

Level 1: Workers and Office Sessions

  • ["ADD_WORKER", workerId, position, compensation] adds a new worker and stores the worker's position and compensation. If workerId already exists, leave the system unchanged and return false; otherwise return true. Worker IDs and positions contain only English letters and spaces.
  • ["REGISTER", workerId, timestamp] records an office entry when the worker is outside and records an exit when the worker is inside. Calls to REGISTER arrive in increasing timestamp order. Return invalid_request for an unknown worker and registered after a successful entry or exit.
  • ["GET", workerId] returns the worker's total time in the office using completed sessions only. A current session without an exit contributes nothing. Return the empty string when the worker does not exist.

Level 2: Ordered Worker Statistics

  • ["TOP_N_WORKERS", n, position] returns at most n workers whose current position equals position.
  • Order workers by completed office time in descending order. Break equal-time ties by worker ID in ascending alphabetical order.
  • Format the result as workerId1(time1), workerId2(time2), .... Return every matching worker when fewer than n exist, and return the empty string when there are no matches.
  • A worker with no completed office session has time 0.

Level 3: Promotions and Salary

  • ["PROMOTE", workerId, newPosition, newCompensation, startTimestamp] schedules a new position and compensation. The source guarantees that newPosition differs from the worker's current position and that startTimestamp is greater than the timestamp of the latest REGISTER call for any worker.
  • A scheduled promotion becomes active on the worker's first office entry whose timestamp is at least startTimestamp. A session beginning earlier keeps the previous position and compensation.
  • Return invalid_request when the worker does not exist or already has a promotion waiting to take effect. Return success when the promotion is scheduled.
  • After promotions exist, TOP_N_WORKERS selects workers by current position and ranks them using completed time accumulated in that current position. GET continues to return lifetime completed time across past and current positions.
  • ["CALC_SALARY", workerId, startTimestamp, endTimestamp] returns salary earned between the two timestamps. Only completed office sessions contribute. For each contributing portion of a session, multiply its duration by the compensation attached to that session. Return the empty string for an unknown worker.

FastPrep Runner Interface

The source uses an array of query rows and one string output per query. FastPrep exposes the same operation rows as workerManagementLevel3(String[][] operations) and returns String[]. Numeric arguments are encoded as base-10 strings.

Multipart Series

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.

Constraints

  • 1 <= operations.length <= 500, matching the source's query-count bound.
  • Every row uses an operation available at this level, has the documented arity, and satisfies the source-stated operation preconditions.
  • Every numeric argument is a valid base-10 integer string.
  • Worker IDs and positions contain only English letters and spaces.
  • All REGISTER calls are supplied in increasing timestamp order.
  • Each PROMOTE uses a new position different from the worker's current position.
  • A promotion's startTimestamp is greater than the timestamp of the latest prior REGISTER call for any worker.
  • Each salary query satisfies endTimestamp > startTimestamp >= 0.

More Ramp problems

See Ramp hiring insights
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…