Practice/Google/Find Top K Chat Contributors
CodingOptional
You are analyzing activity data from a team messaging platform. Given a list of messages where each message is represented by the username of the person who sent it, identify the top k most active contributors based on message count. Return the result in reverse order of their activity ranking (least active among the top k first, most active last).
For example, if the top 3 contributors have message counts of 10, 8, and 5 respectively, you should return them in the order: contributor with 5 messages, contributor with 8 messages, contributor with 10 messages.
Example 1:
` Input: messages = ["alice", "bob", "alice", "charlie", "alice", "bob"], k = 2 Output: ["bob", "alice"] Explanation:
Example 2:
Input: messages = ["user1", "user2", "user1"], k = 3 Output: ["user2", "user1"] Explanation: Only 2 unique contributors exist, so return both in reverse order. user1 has 2 messages, user2 has 1 message.
Example 3:
Input: messages = [], k = 5 Output: [] Explanation: No messages means no contributors.
Example 4:
` Input: messages = ["anna", "ben", "cara", "anna"], k = 2 Output: ["cara", "anna"] Explanation: