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 givenworkerId,position, andcompensation.- Return
"false"without making changes if theworkerIdis already registered. - Return
"true"if the worker was added successfully. workerIdandpositionare guaranteed to contain only English letters and spaces.
- Return
-
String registerWorker(String workerId, int timestamp)— records an office entry or departure for the specified worker at the giventimestamp. Calls toregisterWorkerare provided in increasing order oftimestamp.- If the
workerIdis 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.
- If the
-
int get(String workerId)— should return a number representing the total calculated amount of time that theworkerIdspent 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
workerIddoesn't exist within the system, return-1.
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected