You are given a list of messages, where each message is represented as a triplet: [<sender>, <receiver>, <message>]. For any given sender-receiver pair, if the sender transmits multiple messages to that same receiver, those messages are treated as duplicates (spam).
Your goal is to determine the top k receivers who have obtained the most unique (non-spam) messages. A unique message is defined by a distinct sender-receiver pair—multiple messages from the same sender to the same receiver count only once. If there is a tie in the count of unique messages, the receivers should be ranked alphabetically (lexicographically smaller names come first).
Constraints:
k will never exceed the total number of unique receivers.Example 1:
messages = [ ["Jack", "Mary", "I love you"], ["Jack", "Mary", "I miss you"], ["Jack", "Rose", "Hello"], ["Alice", "Mary", "Are you available"], ["Bob", "Rose", "Hi there"], ["John", "Lisa", "Hi there"], ["John", "Lisa", "Hi there!"], ["John", "Lisa", "Hi there!!"], ["John", "Lisa", "Hi there!!!"] ], k = 2
["Mary", "Rose"]
"Mary" receives unique messages from "Jack" and "Alice" (count = 2). "Rose" receives unique messages from "Jack" and "Bob" (count = 2). "Lisa" only receives messages from "John" (count = 1). Since "Mary" and "Rose" tie with a count of 2, the lexicographically smaller name "Mary" is placed first.
Example 2:
messages = [ ["Jack", "Mary", "I love you"], ["Jack", "Rose", "I miss you"], ["Jack", "Alice", "Let's have dinner tonight"], ["Alice", "Mary", "Are you available"] ], k = 2
["Mary", "Alice"]
Example 3:
messages = [ ["Jack", "Mary", "Hello"], ["Alice", "Rose", "Good morning"], ["Jack", "Mary", "Hi"], ["Alice", "Rose", "Good afternoon"], ["Bob", "Tom", "Hi Tom"], ["Jack", "Mary", "Hey"], ["Charlie", "Tom", "Hello Tom"], ["Charlie", "Jack", "Hello Jack"] ], k = 3
["Tom", "Jack", "Mary"]