Smart Queue of Latest Prices
Updated
Problem statement
Price updates for stock tickers arrive one at a time. Implement a smart queue that keeps the tickers in the order they arrive but holds only the most recent price for each ticker, and process operations on it. Each ticker is an integer id. The queue starts empty.
Each operation is one of:
[0, ticker, price]: push. Iftickeris already waiting in the queue, replace its price withpriceand keep its place. Otherwise addtickerwithpriceat the back. Nothing is recorded.[1]: pop. If the queue is not empty, remove the ticker at the front and record[ticker, price]with its latest price. Otherwise record an empty list[].
A popped ticker is no longer waiting, so a later push of it goes to the back. Prices can be negative. Return the recorded lists in operation order. Each operation should take O(1) average time.
Function
smartQueue(operations: int[][]) → int[][]Examples
Example 1
operations = [[0,1,100],[0,2,200],[0,1,105],[1],[0,3,300],[0,2,210],[1],[1],[1]]return = [[1,105],[2,210],[3,300],[]]Ticker 1 arrives first, then ticker 2. The second push of ticker 1 only changes its price to 105, so the first pop records [1, 105]. Ticker 3 arrives next, and the push of ticker 2 with 210 keeps ticker 2 ahead of ticker 3. The next two pops record [2, 210] and [3, 300], and the last pop finds the queue empty, so it records [].
Example 2
operations = [[0,7,-5],[0,4,3],[1],[0,7,-8],[0,4,-1],[1],[1]]return = [[7,-5],[4,-1],[7,-8]]The first pop records [7, -5]. Ticker 7 is no longer waiting, so its next push puts it at the back, behind ticker 4. The push of ticker 4 with -1 only changes its price. The pops record [4, -1] and then [7, -8].
Example 3
operations = [[1],[0,0,0],[1]]return = [[],[0,0]]The first pop finds the queue empty and records []. Ticker 0 with price 0 is then pushed and popped as [0, 0].
Constraints
1 <= operations.length <= 2 * 10^4- Each operation is
[0, ticker, price]or[1]. 0 <= ticker <= 10^5-10^9 <= price <= 10^9
More Citadel Phone Screen questions
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Rate Limiter with a Sliding Window per ClientStackAdapt · PHONE SCREENStackAdapt interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
- Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Dynamic Least-Loaded Job DispatcherCresta · PHONE SCREENCresta interview questions
- Restaurant WaitlistGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Sliding-Window Rate LimiterUber · PHONE SCREENUber interview questions
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
- Recent Advertisement Click CountsAmazon · PHONE SCREEN
- Recent Event Stream QueriesSnowflake · PHONE SCREENSnowflake interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences