A docs site logs every search query in queries. The home page shows the k most popular ones.
Write topQueries(queries, k) that returns the k queries searched most often, from most to least searched. Break ties by putting the query that comes first in normal string order (<) first, so uppercase letters come before lowercase.
Input: queries = ["css grid","flexbox","css grid","react","flexbox","css grid"], k = 2 Output: ["css grid","flexbox"]
css grid was searched 3 times and flexbox 2 times.
Input: queries = ["b","a","c","a","b","c"], k = 2 Output: ["a","b"]
All three tie at 2, so they're ordered a, b, c and the first two are kept.
1 <= queries.length <= 10^51 <= k <= the number of distinct queriesRun tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #18 Top Searched Queries. 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.