Drill

ProblemsGo › billing

Early payment discount

mediumbillingMathGo

A vendor rewards early payment: the further ahead the payment, the larger the discount off the subtotal.

earlyDiscount(subtotal: int, daysEarly: 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 earlyDiscount(subtotal int, daysEarly int) int {
	
}

Worked examples

CallResult
earlyDiscount(10000, 10)200
earlyDiscount(5000, 5)50
earlyDiscount(7500, 15)150
earlyDiscount(999, 3)0

Hint

Check the thresholds from largest to smallest.

Reference solution in Go
func earlyDiscount(subtotal int, daysEarly int) int {
	if daysEarly >= 10 {
		return subtotal * 2 / 100
	}
	if daysEarly >= 5 {
		return subtotal / 100
	}
	return 0
}

The same problem in another language

More billing problems in Go