Correctable Stock Price Tracker
Updated
Problem statement
Process a parsed stock-price feed. Each operation is either SET timestamp price, which inserts or corrects that timestamp's price, or DELETE timestamp, which removes the timestamp if present.
After every operation, return [latestPrice, minimumPrice, maximumPrice]. The latest price belongs to the greatest stored timestamp. When no prices remain, return [-1,-1,-1].
Timestamps and prices are integers. Operations appear in feed order, which need not match timestamp order.
Function
trackStockPrices(operations: String[]) → int[][]Examples
Example 1
operations = ["SET 1 10","SET 2 5","SET 1 3","DELETE 2"]return = [[10,10,10],[5,5,10],[5,3,5],[3,3,3]]The third operation corrects timestamp 1; deleting timestamp 2 makes timestamp 1 latest again.
Example 2
operations = ["SET 5 7","DELETE 5"]return = [[7,7,7],[-1,-1,-1]]Deleting the sole price empties the tracker.
Example 3
operations = ["DELETE 9","SET 3 4"]return = [[-1,-1,-1],[4,4,4]]Deleting an absent timestamp is a no-op.
Constraints
0 <= operations.length <= 2000.1 <= timestamp, price <= 10^9.- Every operation is exactly
SET t porDELETE t.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Spreadsheet Formula DependenciesCitadel · PHONE SCREENCitadel interview questions
- Randomized String MultisetLinkedIn · PHONE SCREENLinkedIn interview questions
- Least Frequently Used CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Dynamic Least-Loaded Job DispatcherCresta · PHONE SCREENCresta interview questions
- Sparse Vector and Matrix OperationsBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions