All Questions
Next Question
Most Traded
00:00:00
Parts
Part 1
Given a stream of stock data, create a data structure that can efficiently handle the following functions:
execute_trade(ticker, volume)
- store the trade that has occurredmost_traded(k)
- return the most traded stocks by volume. The return format should be a list of strings with each string being formatted as:<TICKER> <VOLUME>
Example:
st = StockTracker() st.execute_trade('TSLA', 1000) st.execute_trade('NFLX', 700) st.execute_trade('TSLA', 200) st.execute_trade('META', 1400) st.most_traded(2) # This should return the following: # META 1400 # TSLA 1200
Complete the following class for your solution
from typing import List class StockTracker: def __init__(self) -> None: pass def execute_trade(self, ticker: str, volume: int) -> None: pass def most_traded(self, k: int) -> List[str]: pass