Problem · Hash Table

Worker Management, Part 1: Office Registration

Learn this problem
EasyAnthropicOA

Problem statement

Build the first level of a worker management system. Process each operation in order and return one string result per operation.

Operations

  • ["ADD_WORKER", worker_id, position, compensation]: add a worker and save the position and hourly compensation. Return true on success or false if the ID already exists.
  • ["REGISTER", worker_id, timestamp]: toggle the worker's office state. When outside, record an entry; when inside, close the session. Return registered, or invalid_request if the worker does not exist. REGISTER timestamps are strictly increasing.
  • ["GET", worker_id]: return the total time from completed office sessions. An unfinished visit contributes zero. Return an empty string for a missing worker.

Worker IDs and positions contain only English letters and spaces.

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.

More Anthropic problems

drafts saved locally
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