__ Problem:-__

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.

**Example**

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

names

Returns

string]: an alphabetically ascending array of customer names

Constraints

• 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.

__Code:-__

def mostActive(customers):

dic={}

n=len(customers)

for i in customers:

if i not in dic:

dic[i]=1

else:

dic[i]+=1

ans=[]

for i in dic:

a=(dic[i]*100)/n

if(a>=5):

ans.append(i)

ans.sort()

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()

customers.append(customers_item)

result = mostActive(customers)

fptr.write('\n'.join(result))

fptr.write('\n')

fptr.close()

__Recommended Post:__

__Key points:-__

- How to set limit in the floating value in python
- What is boolean data type
- How to print any character without using format specifier
- How to check that given number is power of 2 or not
- How to fix limit in double and floating numbers after dot (.) in c++
- How to print a double or floating point number in scientific notation and fixed notation
- How to take input a string in c
- How to reduce the execution time of program in c++.

__Cracking the coding interview:-__

__Array and string:-__

__Tree and graph:-__

__Hackerearth Problems:-__

- Very Cool numbers | Hacker earth solution
- Vowel Recognition | Hackerearth practice problem solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution
- Minimum addition | Hackerearth Practice problem
- The magical mountain | Hackerearth Practice problem
- The first overtake | Hackerearth Practice problem

__Hackerrank Problems:-__- Playing With Characters | Hackerrank practice problem solution
- Sum and Difference of Two Numbers | hackerrank practice problem solution
- Functions in C | hackerrank practice problem solution
- Pointers in C | hackerrank practice problem solution
- Conditional Statements in C | Hackerrank practice problem solution
- For Loop in C | hackerrank practice problem solution
- Sum of Digits of a Five Digit Number | hackerrank practice problem solution
- 1D Arrays in C | hackerrank practice problem solution
- Array Reversal | hackerrank practice problem solution
- Printing Tokens | hackerrank practice problem solution
- Digit Frequency | hackerrank practice problem solution
- Calculate the Nth term | hackerrank practice problem solution

__Data structure:-__

- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- Minimum weight of spanning tree
- Preorder, inorder and post order traversal of the tree

__ MCQs:-__

## 0 Comments