Dynamic Programming21 sections · 916 units
Open in Course

Challenge: Variable Window Size

Dynamic window bounds

What if the window size varies? At position ii, valid j[li,ri]j \in [l_i, r_i] where bounds depend on ii. If lil_i is non-decreasing, the left side still slides right. Pop expired elements from front as usual.

If rir_i is non-decreasing, new elements can be added in order. Standard monotonic queue works. If bounds are arbitrary, monotonic queue doesn't directly apply. Consider segment trees or other structures.