FastPrepMoving Average of a Data Stream
Problems/Moving Average of a Data Stream

Moving Average of a Data Stream

Squarepoint Capital logoSquarepoint Capital● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Squarepoint Capital first-round video interview for an experienced data platform role. The second coding question was described as roughly the well-known moving average of a data stream: keep the average of the last few numbers as new numbers arrive. The candidate explained the idea but ran out of time to code it.

The report gives no other details. Here, you get the window size and the whole stream as an array, and you return the average after each number, instead of writing a class with a next method. Before the window fills, the average uses all numbers so far. Answers within 10^-5 are accepted, and the limits are our own.

Our version is about 80% the same as the reported question.

Integers arrive one at a time in a stream. You are given a window size size and the whole stream as the array values, in the order the numbers arrive.

Right after each number arrives, report the average of the last size numbers of the stream. If fewer than size numbers have arrived so far, report the average of all of them.

Return an array answer where answer[i] is the average reported right after values[i] arrives. An answer within 10^-5 of the correct value is accepted; for values larger than 1 in size, the allowed error is 10^-5 times the correct value.

Function

movingAverage(size: int, values: int[]) → double[]

Examples

Example 1

size = 3values = [4,10,-2,7,1]return = [4.0,7.0,4.0,5.0,2.0]
  • After 4: the window is [4], average 4.0. After 10: [4, 10], average 7.0.
  • After -2: [4, 10, -2], average 12 / 3 = 4.0. The window is now full.
  • After 7: 4 leaves, so the window is [10, -2, 7], average 5.0.
  • After 1: 10 leaves, so the window is [-2, 7, 1], average 2.0.

Example 2

size = 1values = [5,-3]return = [5.0,-3.0]

With size = 1, each average is just the newest value.

Example 3

size = 5values = [1,1,2,2]return = [1.0,1.0,1.3333333333333333,1.5]

Only four values arrive, fewer than size = 5, so each answer averages everything so far: 1 / 1, 2 / 2, 4 / 3 and 6 / 4.

Constraints

  • 1 <= size <= 1000
  • 1 <= values.length <= 1000
  • -10^5 <= values[i] <= 10^5

More Squarepoint Capital Phone Screen questions

  • Lazy Filter over a GeneratorPHONE SCREEN · Seen Nov 2026
  • Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
  • Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
  • Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
  • Combine Two Index SequencesPHONE SCREEN · Seen Aug 2026
  • Parse, Normalize, and Combine PolynomialsPHONE SCREEN · Seen Aug 2026
  • Sorted Insertion SnapshotsPHONE SCREEN · Seen Aug 2026
  • Strong and Weak Reference LifecyclePHONE SCREEN · Seen Aug 2026
  • Target Sum Across Two Sorted ArraysPHONE SCREEN · Seen Aug 2026
  • Classify Heap Addresses from a Memory SnapshotPHONE SCREEN · Seen Nov 2025

Similar questions at other companies

  • Three Calls Within Three SecondsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Sliding Window Average (Meta Canada, E4/E5 :)Meta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Rolling Hit CounterDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
  • Per-Client API Rate LimiterDocker · PHONE SCREEN
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
  • Rolling CSAT TrackerDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Sliding-Window Rate LimiterUber · PHONE SCREENUber interview questions

Interview reports that mention this question

  • Squarepoint Capital Data Products First Round: 1 Experience

Squarepoint Capital interview experiences

  • Squarepoint Capital C++ and Python SWE Interviews: 7 Experiences
  • Squarepoint Campus SDE Interviews: 7 Experiences (Part 2 of 2)
  • Squarepoint Capital New Grad SDE OA: 5 Experiences (Part 1 of 2)
All Squarepoint Capital interview questionsSee Squarepoint Capital hiring insights
Saved
class Solution {
    public double[] movingAverage(int size, int[] values) {
        // Write your code here.
    }
}
Checking account…