Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

(This question is a variation of the LeetCode question 692. Top K Frequent Words. If you haven't completed that question yet, it is recommended to solve it first.)

You are given an array of messages where each element is a triplet: [<sender>, <receiver>, <message>]. For each sender-receiver pair, if the sender sends multiple messages to the same receiver, they are considered duplicates (spam).

Test Cases
Input
Output
Expected