Quant Memo
Coding/●●●●

Count runs with at most k losing days

Asked at Two Sigma, HRT

Given a series of daily returns and a budget k, count how many contiguous runs contain at most k losing days (returns below zero). Every non-empty contiguous run counts if it satisfies the constraint.

returns = [1, -1, 2, -3], k = 1
-> 8

Return the number of contiguous runs with at most k negatives. Aim for O(n)O(n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions