Trade Volume Leaderboard
Updated
Problem statement
Process a sequence of company trade-volume operations. The leaderboard starts empty.
["TRADE", company, volume]adds the positive integervolumeto that company's cumulative traded volume.["TOP", k]requests the current topkcompanies.
For every TOP operation, return one row whose entries have the form "company|cumulativeVolume", ranked by decreasing cumulative volume and then lexicographically by company when volumes tie. Return the query rows in encounter order.
Function
tradeVolumeLeaderboard(operations: String[][]) → String[][]Examples
Example 1
operations = [["TRADE","MSFT","900"],["TRADE","APPL","300"],["TRADE","GOOG","1000"],["TRADE","APPL","400"],["TRADE","META","200"],["TRADE","BA","500"],["TOP","2"]]return = [["GOOG|1000","MSFT|900"]]APPL accumulates to 700, but GOOG and MSFT have the two largest totals.
Example 2
operations = [["TRADE","A","5"],["TRADE","B","7"],["TOP","2"],["TRADE","A","4"],["TOP","1"]]return = [["B|7","A|5"],["A|9"]]The second trade raises A's cumulative volume from 5 to 9.
Example 3
operations = [["TRADE","ZZ","10"],["TRADE","AA","10"],["TRADE","MM","10"],["TOP","3"]]return = [["AA|10","MM|10","ZZ|10"]]Equal totals are ordered lexicographically by company.
Constraints
1 <= operations.length <= 100000.- Every operation is
TRADEorTOP. companycontains between1and10uppercase English letters.1 <= volume <= 10^9.- For every query,
1 <= k <=the number of companies seen so far. - Each cumulative volume fits in a signed 64-bit integer.
- At least one
TOPoperation is present.
More Bloomberg LP Onsite Interview questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Top K Upvoted Songs by ArtistAmazon · ONSITE INTERVIEW
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Dynamic Median with Additions and DeletionsByteDance · ONSITE INTERVIEWByteDance interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Thread-Safe LRU Cache with TTLLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Top K Frequent Elements After Each Stream UpdateSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)