Drill

ProblemsGo › billing

Compute the late payment fee

easybillingMathGo

A billing system charges a fixed fee for the first overdue day and a smaller increment for each additional day.

lateFee(daysLate: int) → int

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 lateFee(daysLate int) int {
	
}

Worked examples

CallResult
lateFee(1)2500
lateFee(2)3000
lateFee(5)4500
lateFee(0)0

Hint

Subtract one from the count, multiply the increment, and add the base — but only when positive.

Reference solution in Go
func lateFee(daysLate int) int {
	if daysLate <= 0 {
		return 0
	}
	return 2500 + (daysLate-1)*500
}

The same problem in another language

More billing problems in Go