FastPrepAllocate Orders with FIFO and Pro Rata
Problems/Allocate Orders with FIFO and Pro Rata

Allocate Orders with FIFO and Pro Rata

Akuna Capital logoAkuna Capital● MediumNEW GRADFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in Akuna Capital new grad and full-time phone screens. The reports describe an order allocator that uses FIFO and pro rata rules, followed by questions about making it faster. One author fixed the example quantities. The reports do not say how ties break, how big the requests can be, or what order the output is in. Our version follows the clearest account, which has three phases. It is about 85% the same as the reported question.

You manage one pool of orders. Each order has an ID, a remaining size and its original arrival position. Every order in the pool can already trade with an incoming request. There are no prices or buy/sell sides in this task.

Process commands in order. Each command has three integers:

  • [0, id, size] is an ADD. It adds an order at the end of the arrival order.
  • [1, requested, 0] is a MATCH. It takes units from the pool and returns how many units each order gives.

For a MATCH command, let target = min(requested, total remaining size). Any part of the request that cannot be filled is dropped. It does not wait for future orders. If target = 0, this MATCH returns an empty result.

When the target is positive, run these phases in order:

  1. FIFO: Allocate ceil(2*target/5) units. Take them from the earliest nonempty order (one that still has size left). Then move on to the next order until this amount is filled.
  2. Pro rata: Let budget be the part of the target still unfilled. Let S be the total remaining size after FIFO. An order whose size after FIFO is q gives floor(budget*q/S) units. Use the same budget, the same S and the post-FIFO sizes for every order in this phase. Skip this phase when the budget is zero.
  3. Residual: Rank the nonempty orders by their remaining size after pro rata, largest first. Break ties by original arrival. Walk through this fixed ranking and take one more unit from each order until the target is filled. Do not keep picking whichever order is currently largest. When the residual is positive, it is smaller than the number of nonempty orders, so one pass is enough.

Subtract every allocation from the stored sizes. An order with no size left leaves the pool. The remaining orders keep their original arrival order for later MATCH commands. The residual ranking does not change that order.

Return one result for each MATCH command, in command order. A result holds an [id, allocated] row for each order that gave a positive amount in that MATCH. Add up the three phases into one amount per order, and list the rows in original arrival order. ADD commands produce no result. If there are no MATCH commands, return an empty array.

Do not change commands. Start each call with an empty pool. Each MATCH result shows only that match, and later commands must not change it.

Function

allocateOrders(commands: int[][]) → int[][][]

Examples

Example 1

commands = [[0,101,4],[0,202,9],[0,303,16],[1,11,0]]return = [[[101,4],[202,3],[303,4]]]

The FIFO quota is ceil(2*11/5) = 5. It takes 4 units from order 101 and 1 from order 202. The remaining sizes are 8 and 16.

Pro rata allocates the remaining 6 units: floor(6*8/24) = 2 to order 202 and floor(6*16/24) = 4 to order 303. No residual remains. The total allocations are 4, 3 and 4.

Example 2

commands = [[0,101,4],[0,202,9],[0,303,16],[1,12,0]]return = [[[101,4],[202,3],[303,5]]]

FIFO again takes 4 units from order 101 and 1 from order 202. The remaining sizes are 8 and 16, and 7 units still need to be filled.

The proportional floors give 2 and 4 units. The remaining sizes are then 6 and 12. One residual unit goes to order 303, whose remaining size is larger. The total allocations are 4, 3 and 5.

Example 3

commands = [[0,41,10],[0,7,10],[1,10,0]]return = [[[41,6],[7,4]]]

FIFO takes 4 units from order 41, leaving sizes 6 and 10. The proportional budget is 6: the floors of 6*6/16 and 6*10/16 are 2 and 3.

The remaining sizes are 4 and 7. The last unit goes to order 7. The total allocations are 6 to order 41 and 4 to order 7. Arrival order, rather than ID order, determines the row order.

Constraints

  • 0 <= commands.length <= 60.
  • Each command contains exactly 3 integers.
  • Every integer in commands is between 0 and 10^6, inclusive.
  • An ADD is [0, id, size], where id >= 1 and size >= 1. A MATCH is [1, requested, 0], where requested >= 0. No other command form is valid.
  • IDs on ADD commands are unique across the entire batch, including IDs of orders that have already been fully allocated.

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

  • Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
  • Finish Time of Fixed-Length CPU TasksGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
  • Document Indexer Scheduling MetricsGlean · PHONE SCREENGlean interview questions
  • Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Inventory AllocationAmazon · OA
  • Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Weighted Server Load Balancer with TTLStripe · ONSITE INTERVIEWStripe interview questions
  • Progressive Banking SystemAirbnb · OAAirbnb interview questions
  • Cloud Compute Credits SystemCoinbase · OACoinbase 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 int[][][] allocateOrders(int[][] commands) {
        // write your code here
    }
}
Checking account…