Drill

ProblemsPython › network

Classify a latency measurement

mediumnetworkPython

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

latency_band(latency_ms: int) → string

Solve it in the editor →

Where you start

def latency_band(latency_ms: int) -> str:
    

Worked examples

CallResult
latency_band(0)"fast"
latency_band(100)"fast"
latency_band(250)"normal"
latency_band(999)"normal"

Hint

Check the thresholds from smallest to largest.

Reference solution in Python
def latency_band(latency_ms: int) -> str:
    if latency_ms < 250:
        return "fast"
    if latency_ms < 1000:
        return "normal"
    if latency_ms < 3000:
        return "slow"
    return "timeout"

The same problem in another language

More network problems in Python