FastPrepWorker Management, Part 1: Office Registration

Worker Management, Part 1: Office Registration

Ramp logoRamp● EasyNEW 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 Level 1 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.

FastPrep Runner Interface

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

Multipart Series

Function

workerManagementLevel1(operations: String[][]) → String[]

Examples

Example 1

operations = [["ADD_WORKER","Ashley","Middle Developer","150"],["ADD_WORKER","Ashley","Junior Developer","100"],["REGISTER","Ashley","10"],["REGISTER","Ashley","25"],["GET","Ashley"],["REGISTER","Ashley","40"],["REGISTER","Ashley","67"],["REGISTER","Ashley","100"],["GET","Ashley"],["GET","Walter"],["REGISTER","Walter","120"]]return = ["true","false","registered","registered","15","registered","registered","registered","42","","invalid_request"]

Ashley's completed sessions are [10,25) and [40,67), totaling 42. The entry at 100 is unfinished and does not count.

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.

More Ramp problems

See Ramp hiring insights
public String[] workerManagementLevel1(String[][] operations) {
  // write your code here
}
operations[["ADD_WORKER","Ashley","Middle Developer","150"],["ADD_WORKER","Ashley","Junior Developer","100"],["REGISTER","Ashley","10"],["REGISTER","Ashley","25"],["GET","Ashley"],["REGISTER","Ashley","40"],["REGISTER","Ashley","67"],["REGISTER","Ashley","100"],["GET","Ashley"],["GET","Walter"],["REGISTER","Walter","120"]]
expected["true", "false", "registered", "registered", "15", "registered", "registered", "registered", "42", "", "invalid_request"]
Checking account…