Get Search Results
Learn this problemProblem statement
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.
Function
getSearchResults(words: String[], queries: String[]) → String[][]
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 🌟
Examples
Example 1
words = ["duel", "speed", "dule", "cars"]queries = ["spede", "deul"]return = [["speed"], ["duel", "dule"]]
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
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.
More JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Find Total WeightSeen Jun 2025