Drill

ProblemsGo › machines

Is maintenance due yet

easymachinesMathGo

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.

maintenanceDue(lastService: int, intervalDays: int, today: int) → bool

Go needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

func maintenanceDue(lastService int, intervalDays int, today int) bool {
	
}

Worked examples

CallResult
maintenanceDue(100, 10, 110)true
maintenanceDue(100, 10, 109)false
maintenanceDue(100, 10, 100)false
maintenanceDue(100, 0, 50)true

Hint

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

Reference solution in Go
func maintenanceDue(lastService int, intervalDays int, today int) bool {
	if intervalDays <= 0 {
		return true
	}
	if today < lastService {
		return false
	}
	return today-lastService >= intervalDays
}

The same problem in another language

More machines problems in Go