Quant Memo
Coding/●●●●●

Total traded volume per symbol

You have a list of executed trades, each a (symbol, quantity) pair. Aggregate the total quantity per symbol and return the symbols ranked by total volume, largest first. Break ties alphabetically by symbol.

trades = [("AAPL", 100), ("MSFT", 50), ("AAPL", 30)]
-> [("AAPL", 130), ("MSFT", 50)]

Return the list of (symbol, total_volume) sorted by volume descending, ties broken by symbol ascending. Aim for O(nlogn)O(n \log n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions