FastPrepAverage Prices from Broker Quotes
Problems/Average Prices from Broker Quotes

Average Prices from Broker Quotes

Akuna Capital logoAkuna Capital● MediumNEW GRADFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reports ask you to load broker quotes and work out the average buy or sell price for a number of shares, including cases with too few shares. They do not fully give the quote fields, the order of prices, the weighting, how queries behave, the limits or the precision.

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

You are given broker quotes for one stock. Each row of quotes is [bidPrice, bidSize, askPrice, askSize]. The bid side offers to buy up to bidSize shares at bidPrice. The ask side offers to sell up to askSize shares at askPrice.

Each row is a separate broker. If two rows are identical, both still count. The rows may be in any order, and some sizes may be zero. Bid and ask quantities are independent.

Each row of queries is [side, shares]:

  • side = 0 asks for the average price to buy shares shares. Use the lowest ask price first, then the next lowest.
  • side = 1 asks for the average price to sell shares shares. Use the highest bid price first, then the next highest.

For each query, take as many shares as needed from each price in that order. You may use only part of the last broker's available size. A zero size supplies no shares on that side. The order of brokers with the same price cannot change the average.

If that side has enough shares, return the total of price * sharesTaken divided by the requested share count. Weight prices by the number of shares used. If that side has fewer shares than requested, return -1 for the query. Do not return the average of a partial fill.

Every query starts from all of the original quotes. A query does not use up any shares, so later queries see the same sizes on both sides. Bids are never matched against asks, even when a bid price is above an ask price. Keep the two sides separate.

Return one result per query, in query order. If there are no queries, return an empty array. Do not change either input. Each call to your function starts fresh and returns a new array.

Let exact be the true answer for a query: its average or -1. Your result answer is accepted when |answer - exact| <= 0.000000001 * max(1, |exact|).

Function

brokerAveragePrices(quotes: int[][], queries: int[][]) → double[]

Examples

Example 1

quotes = [[100,4,105,3],[102,2,103,4],[99,5,104,2]]queries = [[0,5],[1,5],[0,10],[1,11]]return = [103.2,100.8,-1.0,99.9090909090909]

To buy 5 shares, take 4 at 103 and 1 at 104. The cost is 4*103 + 104 = 516, so the average is 516/5 = 103.2.

To sell 5 shares, use 2 at 102 and 3 at 100. The average is (2*102 + 3*100)/5 = 100.8.

There are only 9 ask-side shares, so buying 10 returns -1. The bid side has 11 shares. Selling all 11 gives (2*102 + 4*100 + 5*99)/11 = 1099/11, about 99.9090909091.

Example 2

quotes = [[50,2,51,1],[50,3,52,1]]queries = [[0,2],[1,4],[1,6],[0,2]]return = [51.5,50.0,-1.0,51.5]

Buying 2 shares uses 1 at 51 and 1 at 52, for an average of 51.5. Both buy queries return the same answer because each query uses the full snapshot.

The bid side has 5 shares, all at 50. Selling 4 has average 50, while selling 6 returns -1.

Example 3

quotes = []queries = [[0,1],[1,1]]return = [-1.0,-1.0]

No brokers supply any shares. Each positive buy or sell request returns -1.

Constraints

  • 0 <= quotes.length <= 60.
  • 0 <= queries.length <= 60.
  • Each quote contains exactly 4 integers.
  • Each query contains exactly 2 integers.
  • Every integer in quotes and queries is between 0 and 10^6, inclusive.
  • In each quote, the price fields at positions 0 and 2 are at least 1.
  • Each query is [side, shares], where side is 0 or 1 and shares >= 1.

More Akuna Capital Phone Screen questions

  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
  • Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Sep 2026
  • Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
  • Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
  • Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
  • Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
  • Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025

Similar questions at other companies

  • Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Maintain a Consistent-Hashing RingCohesity · ONSITE INTERVIEW
  • Choose ContainersIMC Trading · OAIMC Trading interview questions
  • Minimum Operations to Make All Array Elements EqualIBM · OAIBM interview questions
  • Calculating QuantilesIndeed · OAIndeed interview questions
  • Count Lamps Lighting Each PointCapital One · OACapital One interview questions
  • Minimum Cost to Make Array EqualWalmart · OAWalmart interview questions
  • Use Minimum TokensAmazon · OA
  • Log Analyzer: Busiest Service in a Rolling WindowByteDance · PHONE SCREENByteDance interview questions

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
  • Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public double[] brokerAveragePrices(int[][] quotes, int[][] queries) {
        // write your code here
    }
}
Checking account…