A social app's sidebar shows the k hashtags used most in the last hour. You get every use as a string in tags.
Write trending(tags, k) that returns the k most used hashtags, most used first. When two hashtags are used the same number of times, the one that comes first in normal string order (<) goes first. k is between 1 and the number of different hashtags.
Input: tags = ["css","js","css","html","js","css"], k = 2 Output: ["css","js"]
css is used 3 times and js twice.
Input: tags = ["vue","react","svelte","react","vue"], k = 2 Output: ["react","vue"]
react and vue are tied at 2; react comes first alphabetically.
1 <= tags.length <= 10^51 <= k <= number of different tagsRun 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 #384 Trending Hashtags. 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.