Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-381

Sliding Window Allowed Count

Problem

Count the allowed entries of a causal sliding-window mask where position i attends to itself and the window - 1 positions before it, so row i keeps min(i + 1, window) entries.

The signature is sliding_window_count(seq_len, window). Return an integer count without building the mask.

Hint

Each row keeps one more entry than the previous until the window size is reached.

Test cases

case 1
in: [4,2]
expected: 7
case 2
in: [5,1]
expected: 5
case 3
in: [3,3]
expected: 6
case 4
in: [1,5]
expected: 1
Starter codePython
def sliding_window_count(seq_len, window):
    # Your code here
    pass

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