NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

Introduce operations to add workers, record when they enter and leave the office, and retrieve the total time they have worked.

  • boolean addWorker(String workerId, String position, int compensation) — adds a worker to the system using the given workerId, position, and compensation.

    • Return "false" without making changes if the workerId is already registered.
    • Return "true" if the worker was added successfully.
    • workerId and position are guaranteed to contain only English letters and spaces.
  • String registerWorker(String workerId, int timestamp) — records an office entry or departure for the specified worker at the given timestamp. Calls to registerWorker are provided in increasing order of timestamp.

    • If the workerId is not registered, return "invalid_request" without making changes.
    • If the worker is outside the office, record an entry.
    • If the worker is already inside the office, record a departure.
    • Return "registered" when the entry or departure has been recorded successfully.
  • int get(String workerId) — should return a number representing the total calculated amount of time that the workerId spent in the office.

    • The amount of time is calculated using finished working sessions only. It means that if the worker has entered the office but hasn't left yet, this visit is not considered in the calculation.
    • If the workerId doesn't exist within the system, return -1.
Test Cases
Input
Output
Expected