Drill

ProblemsC# › production

Find the bottleneck

mediumproductionArraysC#

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

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

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.

Solve it in Python →

Where you start

public string SlowestStation(List<Station> stations) {
    
}

Worked examples

CallResult
SlowestStation(new List<Station> { new Station("press", 12), new Station("weld", 30), new Station("pack", 9) })"weld"
SlowestStation(new List<Station> { new Station("a", 20), new Station("b", 20) })"a"
SlowestStation(new List<Station> { new Station("broken", 0), new Station("weld", 5) })"weld"
SlowestStation(new List<Station> { new Station("broken", -1) })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 C#
public string SlowestStation(List<Station> stations) {
    string name = null;
    int worst = 0;
    foreach (var s in stations) {
        if (s.SecondsPerUnit <= 0) continue;
        if (s.SecondsPerUnit > worst) { worst = s.SecondsPerUnit; name = s.Name; }
    }
    return name;
}

The same problem in another language

More production problems in C#