Here's an interesting blog post about $O(n)$ rolling window operations: https://byorgey.github.io/blog/posts/2024/11/27/stacks-queues.html