You are implementing an employee management system with four progressive levels of complexity. Each level builds on the previous one, adding new features for tracking employee time, promotions, and compensation.
This is a typical online assessment (OA) problem where levels unlock sequentially. The starter code for Level 1 is provided - you'll extend it for subsequent levels.
Level 1: Add employees and track clock in/out
Level 2: Query total office time and find top K employees by office time
Level 3: Promotions with deferred activation and salary queries for time periods
Level 4: Double salary time periods
Timestamps are in milliseconds
Design data structures that can be extended for future levels
The starter code provides basic structure - extend it as needed
Implement basic employee management functionality including adding employees and tracking when they enter and leave the office.
add_employee(name, position, hourly_salary)
Add a new employee to the system
Store name, position, and hourly salary rate
clock_in(name, timestamp)
Record when employee leaves the office
Store clock in/out pair for later calculations
` ems = EmployeeManagementSystem() ems.add_employee("Alice", "Engineer", 50.0) ems.clock_in("Alice", 1000) ems.clock_out("Alice", 5000)
`
Store employee information
Maintain records of clock in/out times
Handle multiple clock sessions per employee
Can employees clock in multiple times without clocking out?
What happens if clock_out is called without a matching clock_in?
Should we validate timestamps (ensure clock_out is greater than clock_in)?
Support querying employee office time statistics and ranking employees by time spent in the office.
Find the top K employees who have spent the most time in the office
Return list of employee names
Ranked by total office time (descending)
` ems.add_employee("Bob", "Manager", 75.0) ems.clock_in("Bob", 0) ems.clock_out("Bob", 3000) ems.clock_in("Bob", 5000) ems.clock_out("Bob", 9000)
total = ems.get_total_office_time("Bob")
top = ems.top_k_employees_by_office_time(1)
`
Efficiently calculate cumulative office time
Sort employees by time spent in office
Handle edge case when K is greater than number of employees
Implement promotion functionality with deferred activation and support querying total compensation for any time period.
announce_promotion(name, new_position, new_salary)
Announce a promotion for an employee
Promotion does NOT take effect immediately
Promotion takes effect on the next clock in after announcement
New salary applies to all hours worked after promotion takes effect
Calculate total salary earned during time period [start, end]
Formula: Total Salary = Clock Time × Hourly Rate
Must account for different hourly rates if promotions occurred during the period
Only count time when employee was actually in the office (clocked in)
` ems.add_employee("Alice", "Engineer", 50.0) ems.clock_in("Alice", 1000) ems.clock_out("Alice", 3000)
ems.announce_promotion("Alice", "Senior Engineer", 75.0) ems.clock_in("Alice", 5000) # Promotion takes effect now ems.clock_out("Alice", 8000)
salary = ems.query_salary_for_period("Alice", 0, 10000)
`
Store pending promotions
Apply promotion on next clock in
Track hourly rate for each clock session
Calculate salary considering overlapping time periods and rate changes
Store the hourly rate with each clock record to handle salary changes between sessions:
employee.clock_records.append((clock_in, clock_out, hourly_salary_at_time))
Support designating certain time periods as double salary periods, where employees earn twice their normal hourly rate.
Hours worked during double salary periods earn double the normal rate
Handle cases where work sessions overlap with double salary periods
Handle cases where promotions and double salary periods interact
` ems.add_employee("Charlie", "Engineer", 50.0) ems.define_double_salary_period(2000, 4000)
ems.clock_in("Charlie", 1000) ems.clock_out("Charlie", 5000)
salary = ems.query_salary_for_period("Charlie", 1000, 5000)
`
Store multiple double salary periods
Segment work periods at double salary boundaries
Calculate each segment separately with correct multiplier
Handle overlapping double salary periods