Most Active Customers Certificate Answer

This Python script is designed to identify the most active customers from a list. The activity of a customer is determined by the frequency of their appearance in the list. A customer is considered 'most active' if their frequency is equal to or greater than 5% of the total number of customers.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the Most Active Customers Certificate Answer from HackerRank using CodeRankGPT:

The solution works by using a dictionary to count the frequency of each customer in the list. It then filters out the customers whose frequency is less than 5% of the total number of customers. The remaining customers are considered the 'most active' and are returned as a sorted list. The key data structure used here is a dictionary, which provides an efficient way to count the frequency of elements in a list.


import math
import os
import random
import re
import sys

from collections import defaultdict

def mostActive(customers):
    d = defaultdict(int)
    for c in customers:
        d[c] += 1
    return sorted([c for c, cnt in d.items() if cnt / len(customers) >= 0.05])

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

If you have a HackerRank Certification test or a coding interview coming up, you can use CodeRankGPT to your advantage. It will assist you during your test and help ensure you get the certification or the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform