Drill

ProblemsC++ › network

Classify a latency measurement

mediumnetworkMathStringsC++

Monitoring dashboards colour-code every request by how long it took. Bucket the latency into a human-readable band.

latencyBand(latencyMs: int) → 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::string latencyBand(int latencyMs) {
    
}

Worked examples

CallResult
latencyBand(0)std::string("fast")
latencyBand(100)std::string("fast")
latencyBand(250)std::string("normal")
latencyBand(999)std::string("normal")

Hint

Check the thresholds from smallest to largest.

Reference solution in C++
std::string latencyBand(int latencyMs) {
    if (latencyMs < 250) return "fast";
    if (latencyMs < 1000) return "normal";
    if (latencyMs < 3000) return "slow";
    return "timeout";
}

The same problem in another language

More network problems in C++