Preparing for your next Quant Interview?
Practice Here!
OpenQuant
All Questions
Next Question
Most Traded
00:00:00
2/10
Algorithmic Programming
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 occurred
  • most_traded(k) - return the kk 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