How many parcels missed the van
Items boarded the van if their ready time is before backstopMinutes. Count how many missed it, so the leftover list can be quoted again.
- ready times are in minutes past midnight.
- An item ready exactly at the backstop still boards.
lateParcels(readyTimes: list<int>, backstopMinutes: 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 lateParcels(List<Integer> readyTimes, int backstopMinutes) {
}
Worked examples
| Call | Result |
|---|---|
lateParcels(Main.<Integer>ls(100, 200, 300), 250) | 1 |
lateParcels(Main.<Integer>ls(250, 250), 250) | 0 |
lateParcels(Main.<Integer>ls(300), 100) | 1 |
lateParcels(Main.<Integer>ls(), 500) | 0 |
Hint
Count the ones that fail the comparison.
Reference solution in Java
int lateParcels(List<Integer> readyTimes, int backstopMinutes) {
int n = 0;
for (int t : readyTimes) if (t > backstopMinutes) n++;
return n;
}