Get Search Results
Implement an autocorrect function that returns all words which are anagrams of a search query. An anagram is any string that can be formed by rearranging the letters of another string.
Given two arrays, words and queries of length n and q, respectively, for each query, return an array of strings that are anagrams of the query, sorted in alphabetical order.
Complete the function getSearchResults in the editor with the following arguments:
string words[n]: the list of words to searchstring queries[q]: the words to search for
Returns
string[q][]: the results for each search query
Grateful beyond words to a wonderful old friend for your kind and generous help 🌟
1Example 1
With words = ["duel", "speed", "dule", "cars"] and queries = ["spede", "deul"]:
- For "spede", the only anagram is "speed"
- For "deul", the anagrams are "duel" and "dule"
Return [["speed"], ["duel", "dule"]].
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n, q ≤ 50001 ≤ length of words[i], length of queries[i] ≤ 100- It is guaranteed that each query word has at least one anagram in words.