Get the latest tech news

Purely Functional Sliding Window Aggregation Algorithm


Competitive Programming in Haskell: stacks, queues, and monoidal sliding windows Suppose we have a list of items of length \(n\), and we want to consider windows (i.e. contiguous subsequences) of width \(w\) within the list.

Today I want to show you how to solve this problem using one of my favorite competitive programming tricks, which fits beautifully in a functional context. Note the restriction to commutative monoids, since the queue elements are stored in different orders in the front and back stacks. If you’d like to try solving some problems using the techniques from this blog post, I can recommend the following (generally in order of difficulty):

Get the Android app

Or read this on Hacker News