FastPrepFastPrep
Problem Brief

Autocorrect Prototype

INTERNFULLTIMEOA

Complete the implementation of an autocorrect function. Given a search query string, the function should return all words which are anagrams.

Given 2 arrays, words[n], and queries[q], for each query, return an array of the strings that are anagrams, sorted alphabetically ascending.

Note: An anagram is any string that can be formed be rearranging the letters of a string.

Function Description

Complete the function getSearchResults in the editor.

1Example 1

Input
n = 2, words = ["duel", "speed", "dule", "cars"], queries = ["dpede", "deul"]
Output
[["speed"], ["duel", "dule"]]
Explanation
The only anagram of "speed" is "spede". Both "duel" and "dule" are anagrams of "deul". Return [["speed"], ["duel", "dule"]].

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= n, q <= 5000
  • 1 <= length of words[i], length of queries[i] <= 100
  • It is guaranteed that each query word has at least one anagram in the word list
  • public String[][] autocorrectPrototype(int n, String[] words, String[] queries) {
        // write your code here
    }
    
    Input

    n

    2

    words

    ["duel", "speed", "dule", "cars"]

    queries

    ["dpede", "deul"]

    Output

    [["speed", "duel", "dule"]]

    Sign in to submit your solution.