FastPrepStreaming Average
Problems/Streaming Average

Streaming Average

Xantium logoXantium● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Xantium asked this in a quant researcher video interview. The candidate had to keep a running average of a stream of numbers, one of several short streaming tasks done at speed, followed by a talk about runtime, memory and coping with heavy live market data.

The report names the task only. It gives no interface, number type, window, limits or output format. Here is what we chose. The numbers are integer readings such as price changes in ticks. The stream is a list of add and average calls applied in order to an empty stream, and each average call gives one value. The average covers every value so far (no moving window), repeats included. Values are whole numbers from -1,000,000,000 to 1,000,000,000, written as decimal text with no leading zeros, a minus sign for negatives and plain 0 for zero. There are 2 to 5,000 calls, 1 to 500 of them average calls, and the first call always adds a value. The answer is a list of floating-point numbers, one per average call in call order, and each is accepted within a relative error of 10^-9.

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

A trading system receives a stream of integer readings, for example price changes measured in ticks, which can be negative. At any moment someone may ask for the average of every reading so far.

You are given operations, a list of operations to apply in order to a stream that starts empty. Each operation is one of:

  • ["add", v]: a new value arrives. v is an integer written as a decimal string, such as "12" or "-7".
  • ["average"]: report the average (arithmetic mean) of all values added so far: their sum divided by how many there are.

Every value counts, including repeated ones. Return an array with one value for each "average" operation, in the order the operations appear. A value is accepted if it differs from the exact average a by at most 10^-9 × max(1, |a|).

Function

streamingAverage(operations: String[][]) → double[]

Examples

Example 1

operations = [["add","4"],["add","10"],["average"],["add","-2"],["average"]]return = [7.0,4.0]
  • After 4 and 10 the average is (4 + 10) / 2 = 7.
  • After -2 it is (4 + 10 - 2) / 3 = 12 / 3 = 4.

Example 2

operations = [["add","1"],["add","2"],["add","2"],["average"],["average"]]return = [1.6666666666666667,1.6666666666666667]
  • (1 + 2 + 2) / 3 = 5 / 3, about 1.6667. Asking again without a new value gives the same answer.

Example 3

operations = [["add","-3"],["add","-4"],["average"]]return = [-3.5]
  • (-3 - 4) / 2 = -3.5. Integer division would give -3 or -4, depending on the language.

Constraints

  • 2 <= operations.length <= 5000
  • Each operations[i] is either ["add", v] or ["average"].
  • Each value v is an integer from -10^9 to 10^9, written in decimal digits with no leading zeros and a minus sign in front when it is negative. Zero is written as "0".
  • Between 1 and 500 of the operations are "average", and the first operation is an "add".

More Xantium Phone Screen questions

  • Streaming Median of Trade PricesPHONE SCREEN · Seen Nov 2026
  • Streaming VWAPPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
  • In-Memory URL ShortenerRevolut · PHONE SCREENRevolut interview questions
  • Accumulate Numeric Value ObjectsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • REST API: Discounted PriceOracle · OAOracle interview questions
  • Real-Time Temperature Window StatisticsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Pro-Rata Order BookIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
  • Stock System with Updates and Percentage ChangeLead Bank · ONSITE INTERVIEWLead Bank interview questions
  • Equity Price History with O(1) StatisticsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Shuffle With Given Random DrawsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
See Xantium hiring insights
Saved
class Solution {
    public double[] streamingAverage(String[][] operations) {
        // Write your code here.
    }
}
Checking account…