FastPrepAutocorrect Prototype

Autocorrect Prototype

Goldman Sachs logoGoldman SachsEasyINTERNFULLTIMEOA
Learn

Problem statement

You are given a dictionary array words and an ordered array queries. For every query, return all dictionary entries that are anagrams of that query, sorted in ascending lexicographic order.

Two strings are anagrams when one can be formed by rearranging all characters of the other. The outer result must follow query order. The parameter n is the number of queries and satisfies n == queries.length.

Function

autocorrectPrototype(n: int, words: String[], queries: String[]) → String[][]

Examples

Example 1

n = 2words = ["duel", "speed", "dule", "cars"]queries = ["spede", "deul"]return = [["speed"], ["duel", "dule"]]

Query spede is an anagram of speed. Query deul matches both duel and dule, which are returned in ascending order.

Constraints

  • 1 <= words.length <= 5000
  • 1 <= n == queries.length <= 5000
  • 1 <= words[i].length, queries[i].length <= 100
  • Every query has at least one anagram in words.

More Goldman Sachs problems

See Goldman Sachs hiring insights
public String[][] autocorrectPrototype(int n, String[] words, String[] queries) {
    // write your code here
}
n2
words["duel", "speed", "dule", "cars"]
queries["spede", "deul"]
expected[["speed"], ["duel", "dule"]]
Checking account…