Moving average

Computing the running nn-element moving average over an array of length mm efficiently takes:

Show hints (2)+
  1. Don't recompute each window from scratch.
  2. Add the entering element, subtract the leaving one.

Answer

Reveal answer →

O(m) with a sliding-window sum

Want the full step-by-step worked solution? It's part of Premium — along with a worked solution for every question in the bank.

Asked at: Citadel, DRW

Related questions