Working Hours Register
AirbnbOnline assessmentMedium
You are building a register of employee working hours as the class WorkingHoursRegister.
Part 1: Check-ins and worked time
Employees check in and out of work. Implement:
add_employee(employee_id, position, rate)adds an employee with a unique id, a position and a rate, and returnsnull.enter(employee_id, time)records that the employee checks in attimeand returnsnull.exit(employee_id, time)records that the employee checks out attime, ending the session that began at their last check-in, and returnsnull. The session laststimeminus the check-in time.get_worked_time(employee_id)returns the employee's worked time: the total length of their finished sessions. A session that has not been ended yet counts for nothing.
Times are whole numbers in one unit.
- Example 1
- init
[]- operations
[["add_employee",["e1","dev",10]],["enter",["e1",3]],["get_worked_time",["e1"]],["exit",["e1",8]],["get_worked_time",["e1"]],["add_employee",["e2","qa",7]],["get_worked_time",["e2"]],["enter",["e2",0]],["exit",["e2",0]],["enter",["e2",10]],["exit",["e2",14]],["enter",["e2",20]],["exit",["e2",21]],["get_worked_time",["e2"]],["get_worked_time",["e1"]]]- Output
[null,null,0,null,5,null,0,null,null,null,null,null,null,5,5]
Why:
e1checks in at 3, and while the session is open the worked time is 0. After checking out at 8 it is 5.e2has three finished sessions of lengths 0, 4 and 1, so 5; before the first check-in it was 0.
Constraints
0 <= time <= 10^9; every employee is added before any other call names them, and ids are added only once- For each employee, calls alternate
enterandexit, starting withenter, and a call'stimeis at least thetimeof that employee's previous call. Times of different employees are not related 1 <= len(employee_id) <= 32, and an id uses lowercase letters and digits1 <= len(position) <= 32, and a position uses lowercase letters and underscores0 <= rate <= 10^4- At most
2000calls in total
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.