Problems › Python › production
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.
slowest_station(stations: list<Station>) → string?
Where you start
def slowest_station(stations: list[Station]) -> str | None:
Worked examples
| Call | Result |
|---|---|
slowest_station([Station(name="press", seconds_per_unit=12), Station(name="weld", seconds_per_unit=30), Station(name="pack", seconds_per_unit=9)]) | "weld" |
slowest_station([Station(name="a", seconds_per_unit=20), Station(name="b", seconds_per_unit=20)]) | "a" |
slowest_station([Station(name="broken", seconds_per_unit=0), Station(name="weld", seconds_per_unit=5)]) | "weld" |
slowest_station([Station(name="broken", seconds_per_unit=-1)]) | None |
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 Python
def slowest_station(stations: list[Station]) -> str | None:
name = None
worst = 0
for s in stations:
if s.seconds_per_unit <= 0:
continue
if s.seconds_per_unit > worst:
worst, name = s.seconds_per_unit, s.name
return name