Drill

ProblemsPython › machines

Is maintenance due yet

easymachinesPython

A machine logs the day of its last service and a service interval in days. A checker decides whether today it is time to service it again.

maintenance_due(last_service: int, interval_days: int, today: int) → bool

Solve it in the editor →

Where you start

def maintenance_due(last_service: int, interval_days: int, today: int) -> bool:
    

Worked examples

CallResult
maintenance_due(100, 10, 110)True
maintenance_due(100, 10, 109)False
maintenance_due(100, 10, 100)False
maintenance_due(100, 0, 50)True

Hint

Guard the two odd cases first, then compare the gap against the interval.

Reference solution in Python
def maintenance_due(last_service: int, interval_days: int, today: int) -> bool:
    if interval_days <= 0:
        return True
    if today < last_service:
        return False
    return today - last_service >= interval_days

The same problem in another language

More machines problems in Python