This question evaluates a candidate's ability to implement accurate time-based payroll calculations, covering interval arithmetic, proportional pay for partial hours, handling edge cases in start/end times, and designing caching or preprocessing to support repeated cutoff queries.
You are given a list of workers. Each worker has:
id
(string)
hourly_rate
(non-negative number)
start_time
,
end_time
(times such as
"12:00"
,
"22:00"
in 24-hour format)
Assume times are within the same day and end_time > start_time (no overnight shifts). Pay is proportional to time worked.
Write a function that computes the total amount of money paid to all workers for their full shifts.
Input: list of workers
Output: total pay (number)
Write a second function to compute how much to pay workers up to a given cutoff time cutoff_time.
Rules:
cutoff_time
, pay their full shift.
cutoff_time
, pay
0
.
12:00–22:00
and cutoff is
17:00
), include only the portion worked
from start_time up to cutoff_time
.
Input: list of workers, cutoff_time
Output: total pay up to cutoff (number)
If this function is called repeatedly for many different cutoff times, describe (at a high level, in code structure or data structures) how you would cache or preprocess information to avoid recomputing from scratch each time.
(You do not need to use any specific library; just clearly define the approach and expected time/space tradeoffs.)