Dynamic Future Pricing
Updated
Problem statement
A stock has today's price stockPrice and a list of dividends. Each dividend is represented by [amount, day]. Beginning on its payment day, that amount is subtracted from every future price.
Process the operations in order:
UPDATE i amount dayreplaces thei-th dividend, using one-based indexing.PRICE dayasks for the future stock price on that day. Subtract every current dividend whose payment day is at most the queried day.
Return the answers to all PRICE operations in their original order.
Function
futurePrices(stockPrice: long, dividends: long[][], operations: String[]) → long[]Examples
Example 1
stockPrice = 1000dividends = [[100,10],[50,100]]operations = ["PRICE 1","PRICE 10","PRICE 99","PRICE 100"]return = [1000,900,900,850]The first dividend starts affecting the price on day 10, and both dividends affect it beginning on day 100.
Example 2
stockPrice = 500dividends = [[20,5],[30,10]]operations = ["PRICE 10","UPDATE 1 40 12","PRICE 10","PRICE 12","UPDATE 2 5 3","PRICE 2","PRICE 3"]return = [450,470,430,500,495]Moving the first dividend to day 12 removes it from the day-10 query. The second update moves a dividend to day 3.
Constraints
1 <= dividends.length, operations.length <= 10^51 <= stockPrice, amount <= 10^91 <= day <= 10^6- At most
500operations areUPDATEoperations. - Every update index is valid.
- Future prices and cumulative dividend amounts fit in a signed
long.
More Optiver Online Assessment questions
- Chance a Die Game Balance Reaches ZeroOA · Seen Dec 2026
- Chance a Hand of Cards Multiplies to More Than a ThresholdOA · Seen Dec 2026
- Chance a Sum of Random Draws Has a Given Number of DigitsOA · Seen Dec 2026
- Expected Draws to Remove All Green CountersOA · Seen Dec 2026
- Expected Profit of a Doubling Betting SystemOA · Seen Dec 2026
- Expected Steps Until a Random Walk Gets Far From ZeroOA · Seen Dec 2026
- Rolling Until One Face's Own Total Passes a ThresholdOA · Seen Dec 2026
- Two Ranked Teams Meeting in a Random BracketOA · Seen Dec 2026
- Overheat Prevention ControllerOA · Seen Nov 2026
- Power Cell BankOA · Seen Nov 2026
Similar questions at other companies
- Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
- Rolling MetricsAkuna Capital · OAAkuna Capital interview questions
- Leaves Remaining After Wind GustsOpenAI · OAOpenAI interview questions
- Dynamic Wall Building and Range QueryCapital One · OACapital One interview questions
- Hall of Shifting TilesAdobe · OAAdobe interview questions
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
- Dynamic Weighted Range ScoresIntuit · OAIntuit interview questions
- Distribute Elements Into Two Arrays IIRubrik · OARubrik interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Longest Subarray with Sum at Most KGoogle · OAGoogle interview questions