← 返回 rippling 的题目列表Driver Payroll: sum salaries of driving records up to a timestamp
类型:online_judge
Problem: Pay drivers up to a timestamp (payUpUntil)
You are building a simple driver payroll module. The system continuously receives driving records. Each driver may have more than one driving record.
Each driving record contains at least:
driverId: unique driver identifier (string or integer)
startTime: start timestamp
endTime: end timestamp (guaranteed endTime >= startTime)
salary: the total salary amount for this driving record (assume it is precomputed)
Implement:
payUpUntil(t): given a timestamp t, return the total salary payable up to time t.
Payment rules:
A record is payable only if endTime < t (or endTime <= t, depending on the interviewer’s convention).
Each record must be paid at most once: once included in a payUpUntil result, it must not be paid again in future calls.
Data type requirement
Decide whether timestamps should be stored as double or long (to avoid precision issues).
Requirements
Design and implement a data structure/class to:
add driving records (e.g., addRecord(record))
support multiple calls to payUpUntil(t)
payUpUntil(t) should be efficient.
Write test cases to validate correctness.
Constraints / edge cases (assume reasonable defaults)
Records may arrive out of order.
Records from different drivers may interleave.
Multiple records can share the same endTime.
Example (for understanding)
Records:
A: start=1, end=5, salary=100
B: start=2, end=3, salary=30
C: start=6, end=7, salary=50
Calls:
payUpUntil(4) pays B (end=3 < 4), returns 30
payUpUntil(10) additionally pays A and C, returns 150
calling payUpUntil(10) again returns 0 (already paid)
Example
Input
(unit tests within code)
Output
OK