Drill

ProblemsPython › production

Find the bottleneck

mediumproductionPython

On an assembly line the slowest station sets the pace for everything else, so it is the one worth fixing first.

slowest_station(stations: list<Station>) → string?

Solve it in the editor →

Where you start

def slowest_station(stations: list[Station]) -> str | None:
    

Worked examples

CallResult
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

The same problem in another language

More production problems in Python