FastPrepStreaming VWAP
Problems/Streaming VWAP

Streaming VWAP

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 volume-weighted average price up to date as trades streamed in, 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 trade format, no time window, no limits and no output format. Here is what we chose. Each trade is a whole-number price and a whole-number share count. The stream is a list of trade and VWAP calls applied in order to an empty stream, and each VWAP call gives one value. The VWAP covers every trade so far (no window): total price times quantity divided by total quantity. Prices and quantities are 1 to 1,000,000, written as decimal text with no leading zeros. There are 2 to 5,000 calls, 1 to 500 of them VWAP calls, and the first call is always a trade. The answer is a list of floating-point numbers, one per VWAP 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.

The volume-weighted average price (VWAP) of a group of trades is the total money traded divided by the total number of shares traded. For trades with prices p1, p2, ... and quantities q1, q2, ... it is (p1 × q1 + p2 × q2 + ...) / (q1 + q2 + ...). Large trades count for more than small ones.

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

  • ["trade", p, q]: a trade of q shares at price p happens. Both are positive integers written as decimal strings.
  • ["vwap"]: report the VWAP of all trades so far.

Return an array with one value for each "vwap" operation, in the order the operations appear. A value is accepted if it differs from the exact VWAP v by at most 10^-9 × max(1, |v|).

Function

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

Examples

Example 1

operations = [["trade","100","10"],["trade","102","30"],["vwap"],["trade","98","60"],["vwap"]]return = [101.5,99.4]
  • After two trades the total value is 100 × 10 + 102 × 30 = 4060 over 40 shares, so the VWAP is 4060 / 40 = 101.5.
  • The third trade adds 98 × 60 = 5880 over 60 shares: (4060 + 5880) / (40 + 60) = 9940 / 100 = 99.4.

Example 2

operations = [["trade","50","7"],["vwap"],["vwap"]]return = [50.0,50.0]
  • With one trade the VWAP is its price, 50. Asking again without a new trade gives the same value.

Example 3

operations = [["trade","10","1"],["trade","11","2"],["vwap"]]return = [10.666666666666666]
  • (10 × 1 + 11 × 2) / (1 + 2) = 32 / 3, about 10.6667. The plain average of the two prices would be 10.5.

Constraints

  • 2 <= operations.length <= 5000
  • Each operations[i] is either ["trade", p, q] or ["vwap"].
  • Each price p and each quantity q is an integer from 1 to 10^6, written in decimal digits with no leading zeros.
  • Between 1 and 500 of the operations are "vwap", and the first operation is a "trade".

More Xantium Phone Screen questions

  • Streaming AveragePHONE SCREEN · Seen Nov 2026
  • Streaming Median of Trade PricesPHONE 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[] streamingVwap(String[][] operations) {
        // Write your code here.
    }
}
Checking account…