Header Ads Widget

Active Traders certification test problem | Hackerrank Solution


  An institutional broker wants to review their book of customers to see which are most active. Given a list of trades by customer name, determine which customers account for at least 5% of the total number of trades. Order the list alphabetically ascending by name.

n = 23
customers = ["Bigcorp", "Bigcorp", "Acme", "Bigcorp", "Zork", "Zork", "Abc", "Bigcorp", "Acme", "Bigcorp", "Bigcorp", "Zork", "Bigcorp", "Zork", "Zork", "Bigcorp", "Acme", "Bigcorp", "Acme", "Bigcorp", "Acme", "Littlecorp", "Nadircorp"].

Bigcorp had 10 trades out of 23, which is 43.48% of the total trades.

Both Acme and Zork had 5 trades, which is21.74% of the total trades. 

The Littlecorp, Nadir, and Abc had 1 trade each, which is 4.35% of the total trades.

So the answer is ["Acme", "Bigcorp", "Zork"] (in alphabetical order) because only these three companies placed at least 5% of the trades.

Function Description

Complete the function mostActive in the editor below.
mostActive has the following parameter: string customers[n]: an array customer
string]: an alphabetically ascending array of customer names
• 1≤n≤ 105
• 1 slength of customers[1] < 20
• The first character of customers[i] English letter is a capital
• All characters of customers[i] except for the first one are lowercase English letters.
• It is guaranteed that at least one customer makes at least 5% of trades.


def mostActive(customers):
    for i in customers:
        if i not in dic:
    for i in dic:
    return ans

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    customers_count = int(input().strip())

    customers = []

    for _ in range(customers_count):
        customers_item = input()

    result = mostActive(customers)



Recommended Post:

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-


Post a Comment