Tiered Expiring Item Store
Updated
Problem statement
You manage an item store split into levels, ordered from top to bottom. Level i has a fixed, positive capacity of levelCapacities[i] slots.
Write processTieredStore. It handles operations in order and returns one string result for each operation.
Operations
STORE itemId weight expiresAt: If an item with IDitemIdis already stored, return"false". Otherwise, go through the levels from top to bottom, put the item in the first level that has a free slot, and return"true". If every level is full, return"false".RETRIEVE now:- Remove every stored item whose
expiresAtis less than or equal tonow. These items have expired. - Check the levels from top to bottom. A level is eligible when it holds at least one item and at least half of its slots are free. In other words,
2 * freeSlots >= capacity. - Take the first eligible level. Remove its heaviest item that is still stored and return that item's ID. If several items tie for the largest weight, pick the lexicographically smallest ID. That is the ID that comes first in string order: compare the IDs character by character using character codes, and an ID that is the start of a longer ID comes first.
- If no level is eligible, return
"null".
- Remove every stored item whose
State Rules
- A
STOREoperation never removes expired items, because it does not get the current time. - An ID stays taken while its item is stored. This is true even after the item's expiration time has passed, as long as no
RETRIEVEoperation has removed it yet. - An ID can be stored again once its earlier item has been retrieved or removed as expired.
- Every operation adds exactly one entry to the returned array.
Function
processTieredStore(levelCapacities: int[], operations: String[]) → String[]Examples
Example 1
levelCapacities = [4,2]operations = ["STORE a 5 5","STORE b 9 5","STORE c 7 20","STORE d 6 20","STORE e 10 20","RETRIEVE 5","RETRIEVE 5","RETRIEVE 5"]return = ["true","true","true","true","true","c","d","e"]At time 5, items a and b expire and are removed. The top level now has two free slots out of four. That is exactly half, so the level is eligible. It returns c, the heavier of its two items, then d. Once the top level is empty, it is no longer eligible, so the lower level returns e.
Example 2
levelCapacities = [2]operations = ["STORE x 8 3","RETRIEVE 3","STORE x 4 10","RETRIEVE 9","STORE x 6 12","STORE x 7 15","RETRIEVE 12"]return = ["true","null","true","x","true","false","null"]The first x expires when now = 3. It is removed, the level is empty, so the retrieval returns "null" and the ID x can be used again. The second x has not expired at time 9, so it is retrieved. The next store of x succeeds. The store after it returns "false" because that x is still stored. At time 12 that x expires, so the last retrieval returns "null".
Example 3
levelCapacities = [4,2]operations = ["STORE alpha 8 30","STORE beta 8 30","STORE old1 1 5","STORE old2 1 5","STORE gamma 9 6","STORE delta 9 30","RETRIEVE 5","RETRIEVE 5","RETRIEVE 6"]return = ["true","true","true","true","true","true","alpha","beta","delta"]The first retrieval removes the expired items old1 and old2. The top level then has two free slots out of four, so it is eligible. The lower level holds heavier items, but the top level comes first. alpha and beta tie on weight, and alpha comes first in string order, so alpha is returned, then beta. At time 6, gamma expires, the top level is empty, and the lower level returns delta.
Constraints
1 <= levelCapacities.length <= 501 <= levelCapacities[i] <= 10^5- The sum of all level capacities is at most
2 * 10^5. 1 <= operations.length <= 2 * 10^5.- Every operation has valid syntax and is either
STORE itemId weight expiresAtorRETRIEVE now. - Each
itemIdhas length from1through20and contains only letters, digits, underscores, or hyphens. 1 <= weight, expiresAt, now <= 10^9.
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
- 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
- Reverse Nodes in Groups of KPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
- Limit Order Book Matching EngineCitadel · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- Design Authentication ManagerApple · PHONE SCREENApple 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)