Find the bottleneck
On an assembly line the slowest station sets the pace for everything else, so it is the one worth fixing first.
- The bottleneck is the station taking the most seconds per unit.
- If two are equally slow, the one earlier in the line wins.
- Stations quoting zero or fewer seconds are not real measurements and are ignored.
- With nothing measurable, return null.
slowestStation(stations: list<Station>) → string?
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
String slowestStation(List<Station> stations) {
}
Worked examples
| Call | Result |
|---|---|
slowestStation(Main.<Station>ls(new Station("press", 12), new Station("weld", 30), new Station("pack", 9))) | "weld" |
slowestStation(Main.<Station>ls(new Station("a", 20), new Station("b", 20))) | "a" |
slowestStation(Main.<Station>ls(new Station("broken", 0), new Station("weld", 5))) | "weld" |
slowestStation(Main.<Station>ls(new Station("broken", -1))) | (String) null |
Hint
Track the best so far and only replace it on a strictly greater time, which gives the tie-break for free.
Reference solution in Java
String slowestStation(List<Station> stations) {
String name = null;
int worst = 0;
for (Station s : stations) {
if (s.secondsPerUnit <= 0) continue;
if (s.secondsPerUnit > worst) { worst = s.secondsPerUnit; name = s.name; }
}
return name;
}