A chat app shows the most popular emoji reactions in a thread. reactions lists every reaction used, as short names like "thumbs-up".
Write topReactions(reactions, k) that returns the k most used names. Order them by count, highest first; names with equal counts go in dictionary order (by character codes). Aim for O(n) work beyond the final tie ordering.
Input: reactions = ["heart","fire","heart","smile","fire","heart"], k = 2 Output: ["heart","fire"]
heart was used 3 times and fire twice.
Input: reactions = ["b","a","c","a","b"], k = 2 Output: ["a","b"]
a and b are tied at 2, so dictionary order decides.
1 <= reactions.length <= 1000001 <= k <= number of distinct namesRun tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #208 Most Used Reactions. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.