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

std::optional<std::string> slowestStation(std::vector<Station> stations) {
    
}

Worked examples

CallResult
slowestStation(std::vector<Station>{Station{std::string("press"), 12}, Station{std::string("weld"), 30}, Station{std::string("pack"), 9}})std::optional<std::string>(std::string("weld"))
slowestStation(std::vector<Station>{Station{std::string("a"), 20}, Station{std::string("b"), 20}})std::optional<std::string>(std::string("a"))
slowestStation(std::vector<Station>{Station{std::string("broken"), 0}, Station{std::string("weld"), 5}})std::optional<std::string>(std::string("weld"))
slowestStation(std::vector<Station>{Station{std::string("broken"), -1}})std::nullopt

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++
std::optional<std::string> slowestStation(std::vector<Station> stations) {
    std::optional<string> name;
    int worst = 0;
    for (const auto& s : 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++