Skip to content
DeepForgeby svx
All problems
HardNLPnlp-242

Chunk Overlap Coverage

Problem

Compute overlap statistics for sliding windows. Windows start at 0, stride, 2*stride, and so on while the start index is below n_tokens, and each window covers chunk_size tokens capped at n_tokens.

Return [n_chunks, covered] where covered is the number of distinct token positions covered. Return [0, 0] when any size argument is not positive.

Hint

The last window starts at ((n_tokens - 1) // stride) * stride and extends chunk_size positions.

Test cases

case 1
in: [10,4,2]
expected: [5,10]
case 2
in: [10,3,4]
expected: [3,10]
case 3
in: [5,2,3]
expected: [2,5]
case 4
in: [0,4,2]
expected: [0,0]
case 5
in: [4,6,2]
expected: [2,4]
Starter codePython
def chunk_overlap_coverage(n_tokens, chunk_size, stride):
    # Your code here
    pass

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