Drill

ProblemsPython › network

Cache hit ratio in permille

easynetworkPython

A proxy dashboard reports cache efficiency as permille — parts per thousand — so operators can spot a 2 permille dip that a percentage would round away.

cache_hit_permille(hits: int, requests: int) → int

Solve it in the editor →

Where you start

def cache_hit_permille(hits: int, requests: int) -> int:
    

Worked examples

CallResult
cache_hit_permille(500, 1000)500
cache_hit_permille(1, 3)333
cache_hit_permille(0, 100)0
cache_hit_permille(100, 0)0

Hint

Integer division gives the floor you need.

Reference solution in Python
def cache_hit_permille(hits: int, requests: int) -> int:
    if requests <= 0:
        return 0
    return hits * 1000 // requests

The same problem in another language

More network problems in Python