Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Stock Price Fluctuation
Bookmark
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]
Operation
—
Result
—
Latest Timestamp
—
Timestamp → Price (HashMap)
Timestamp
Price
(empty)
Price → Count (Sorted TreeMap)
(empty)
Operation
—
Result
—
Latest Timestamp
—
Timestamp → Price (HashMap)
Timestamp
Price
(empty)
Price → Count (Sorted TreeMap)
(empty)
Operation
update(1, 10)
Result
—
Latest Timestamp
—
Timestamp → Price (HashMap)
Timestamp
Price
1
10
Price → Count (Sorted TreeMap)
(empty)
Operation
update(1, 10)
Result
null
Latest Timestamp
1
Timestamp → Price (HashMap)
Timestamp
Price
1
10
LATEST
Price → Count (Sorted TreeMap)
Price
Count
10
1
MIN
MAX
Operation
update(2, 5)
Result
—
Latest Timestamp
1
Timestamp → Price (HashMap)
Timestamp
Price
1
10
LATEST
2
5
Price → Count (Sorted TreeMap)
Price
Count
5
1
MIN
10
1
MAX
Operation
current()
Result
—
Latest Timestamp
2
Timestamp → Price (HashMap)
Timestamp
Price
1
10
2
5
LATEST
Price → Count (Sorted TreeMap)
Price
Count
5
1
MIN
10
1
MAX
Operation
maximum()
Result
—
Latest Timestamp
2
Timestamp → Price (HashMap)
Timestamp
Price
1
10
2
5
LATEST
Price → Count (Sorted TreeMap)
Price
Count
5
1
MIN
10
1
MAX
Operation
update(1, 3)
Result
—
Latest Timestamp
2
Timestamp → Price (HashMap)
Timestamp
Price
1
10
2
5
LATEST
Price → Count (Sorted TreeMap)
Price
Count
5
1
MIN
10
1
MAX
Operation
update(1, 3)
Result
—
Latest Timestamp
2
Timestamp → Price (HashMap)
Timestamp
Price
1
3
2
5
LATEST
Price → Count (Sorted TreeMap)
Price
Count
3
1
MIN
5
1
MAX
Operation
minimum()
Result
—
Latest Timestamp
2
Timestamp → Price (HashMap)
Timestamp
Price
1
3
2
5
LATEST
Price → Count (Sorted TreeMap)
Price
Count
3
1
MIN
5
1
MAX
Operation
minimum()
Result
3
Latest Timestamp
2
Timestamp → Price (HashMap)
Timestamp
Price
1
3
2
5
LATEST
Price → Count (Sorted TreeMap)
Price
Count
3
1
MIN
5
1
MAX
algo
master
.
io
Step:
Initialize StockPrice with empty HashMap and TreeMap
0 / 29
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 / 29
algo
master
.
io
Step:
Initialize StockPrice with empty HashMap and TreeMap