Defects per million parts
Quality reports the defect rate in parts per million, because "0.03%" is harder to compare across lines than "300 ppm".
- Rounded to the nearest whole ppm, halves going up.
- A run that produced nothing has no rate: return 0.
DefectPpm(defects: int, produced: int) → int
C# 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
public int DefectPpm(int defects, int produced) {
}
Worked examples
| Call | Result |
|---|---|
DefectPpm(3, 10000) | 300 |
DefectPpm(0, 10000) | 0 |
DefectPpm(1, 3) | 333333 |
DefectPpm(2, 3) | 666667 |
Hint
defects * 1000000 / produced, with half the divisor added before dividing so it rounds instead of truncating.
Reference solution in C#
public int DefectPpm(int defects, int produced) {
if (produced <= 0) return 0;
long n = (long) defects * 1000000 + produced / 2;
return (int) (n / produced);
}