Question 2

Given a file (which can be considered as a String with comma delimiter for the complexity of the question) of usernames and a value k, find top k usernames (with number of logins) who logged into the system the most.

For example –

Input:

User (String) = user1, user4, user2, user1, user3, user1, user2, user3

k (int) = 2

Output:

user1 (3)

user2 (2)

user3 (2)

– Both user2 and user3 should be included since both has same number of logins

Write a java method to find the output with best time and space complexity.

[advanced_iframe securitykey=”undefined” src=”https://code.kodnest.com/” width=”100%” height=”600″]

KodNest Training New Batch is starting on 02nd November 2020. Attend one week free demo classes.Register Now

New Report

Close