Sliding Window Technique: From O(n·k) Scans to O(n) in One Pass
TLDR: Instead of recomputing a subarray aggregate from scratch on every shift, maintain it incrementally — add the incoming element, remove the outgoing element. For a fixed window this costs O(1) per shift. For a variable window, expand the right bo...
abstractalgorithms.dev16 min read