Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-200

Prefix Cache Reuse Length

Problem

Compute how many leading tokens two prompts share, which is how much of the KV cache can be reused between them.

The signature is prefix_cache_reuse(prompt_a, prompt_b). Return the length of the longest common prefix.

Hint

Shared system prompts make most requests in a session share long prefixes.

Test cases

case 1
in: [[1,2,3],[1,2,4]]
expected: 2
case 2
in: [[1,2],[3,4]]
expected: 0
case 3
in: [[],[1]]
expected: 0
case 4
in: [[5,5,5],[5,5,5]]
expected: 3
Starter codePython
def prefix_cache_reuse(prompt_a, prompt_b):
    # Your code here
    pass

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