Drill

ProblemsGo › inventory

When to reorder a part

easyinventoryMathGo

Purchasing wants the stock level at which a part should be reordered, so it arrives before the shelf runs dry.

reorderPoint(dailyUse: int, leadDays: int, safety: 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 reorderPoint(dailyUse int, leadDays int, safety int) int {
	
}

Worked examples

CallResult
reorderPoint(10, 3, 5)35
reorderPoint(0, 7, 20)20
reorderPoint(12, 0, 0)0
reorderPoint(-5, 3, 10)10

Hint

dailyUse × leadDays + safety, with each input floored at zero first.

Reference solution in Go
func reorderPoint(dailyUse int, leadDays int, safety int) int {
	clamp := func(v int) int {
		if v < 0 {
			return 0
		}
		return v
	}
	return clamp(dailyUse)*clamp(leadDays) + clamp(safety)
}

The same problem in another language

More inventory problems in Go