Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-220

Prompt Cache Hit Ratio

Problem

Compute the fraction of requests whose full prompt already exists in the cache (exact token-sequence match).

The signature is prompt_cache_hit_ratio(requests, cached). Return a float between 0 and 1.

Hint

Prompt caching trades memory for latency by skipping repeated prefill work.

Test cases

case 1
in: [[[1,2],[3,4],[1,2]],[[1,2]]]
expected: 0.6666666667
case 2
in: [[[1,2]],[]]
expected: 0
case 3
in: [[[1,2],[3,4]],[[1,2],[3,4]]]
expected: 1
case 4
in: [[[1,2]],[[1,2,3]]]
expected: 0
Starter codePython
def prompt_cache_hit_ratio(requests, cached):
    # Your code here
    pass

4 test cases · run your code against them in the editor