Spares to keep for a fleet
To scale a fleet safely, buying 10% extra units as spares keeps the line alive while one fails. Return the total units to purchase.
- Spares are ten percent, rounded up — a single unit has to be available even for a tiny fleet.
- The answer is units plus the rounded-up spare count.
sparesForScale(units: int) → int
Java 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.
Where you start
int sparesForScale(int units) {
}
Worked examples
| Call | Result |
|---|---|
sparesForScale(100) | 110 |
sparesForScale(1) | 2 |
sparesForScale(0) | 0 |
sparesForScale(10) | 11 |
Hint
Ceiling of ten percent in integers is (units + 9) / 10.
Reference solution in Java
int sparesForScale(int units) {
return units + (units + 9) / 10;
}