Feature #5: Top Brokers
We'll cover the following...
Description
The company is doing performance evaluations. Each broker’s increments will be decided based on their level of activity throughout the last quarter. Each broker is assigned a unique ID that can be used to track their progress. Currently, this information is managed using a list. Every time a broker completes a trade, their ID is inserted into this list. Now, the company wants to promote its top k brokers. We have to implement a functionality that will automatically output the top k performers at the end of a quarter.
We’ll be provided with a list of integers representing the brokers’ IDs. Our task is to determine the top k most active brokers based on the number of times their ID occurs in the list.
Solution
We need to find the top k
IDs based on each number’s frequency count.
In this problem, we first need to know the frequency of each number; we can do this using a, HashMap. Once we have the frequency map, the best data structure to keep track of the top k
frequencies is heap. We’ll iterate through the frequency map ...
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy