Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Stock Price Fluctuation
Bookmark
Linear Scan
Lazy Heaps
Sorted Map
Input
Example 1
Multiple Updates
Single Stock
Custom
operations
=
[StockPrice, update, update, current, maximum, update, minimum]
,
values
=
[null, 1,10, 2,5, null, null, 1,3, null]
StockPrice
priceMap (timestamp -> price)
empty
Stored
Writing
Comparing
Stale
Answer
StockPrice
priceMap (timestamp -> price)
empty
Stored
Writing
Comparing
Stale
Answer
update(1, 10)
priceMap (timestamp -> price)
1→10
Stored
Writing
Comparing
Stale
Answer
update(2, 5)
priceMap (timestamp -> price)
1→10
2→5
latest
Stored
Writing
Comparing
Stale
Answer
current()
priceMap (timestamp -> price)
1→10
2→5
latest
Stored
Writing
Comparing
Stale
Answer
maximum()
priceMap (timestamp -> price)
1→10
2→5
latest
maxPrice = 0
Stored
Writing
Comparing
Stale
Answer
maximum()
priceMap (timestamp -> price)
1→10
2→5
latest
maxPrice = 10
Stored
Writing
Comparing
Stale
Answer
update(1, 3)
priceMap (timestamp -> price)
1→3
2→5
latest
Stored
Writing
Comparing
Stale
Answer
minimum()
priceMap (timestamp -> price)
1→3
2→5
latest
Stored
Writing
Comparing
Stale
Answer
minimum()
priceMap (timestamp -> price)
1→3
2→5
latest
minPrice = 3
Stored
Writing
Comparing
Stale
Answer
StockPrice
priceMap (timestamp -> price)
1→3
2→5
latest
Stored
Writing
Comparing
Stale
Answer
algo
master
.
io
Step:
Start with an empty price map
0 / 22
Input
Example 1
Multiple Updates
Single Stock
Custom
operations
=
[StockPrice, update, update, current, maximum, update, minimum]
,
values
=
[null, 1,10, 2,5, null, null, 1,3, null]
0 / 22
algo
master
.
io
Step:
Start with an empty price map