As reported: Wayfair online assessment on HackerRank (2025), 50 minutes, any language, two problems: find all anagrams of a query in a given word list, and a grid shortest-path problem. Reported by an SDE-3 (L3) candidate; the same two-problem OA (a string-anagram problem, described by an L3 candidate as a variation of Group Anagrams, plus a grid BFS) was reported by Software Engineer 2 and L3 candidates.
You are given a list of words words and a list of query words queries. For each query, return all words in words that are anagrams of the query — words made of exactly the same letters with the same counts, in any order.
Return one list per query, in the order of queries.
This is a variation of LeetCode 49 — Group Anagrams.
Example 1
words = ["listen","google","enlist","silent","inlets","banana","tinsel"]
queries = ["silent","elgoog","apple"]
-> [["listen","enlist","silent","inlets","tinsel"], ["google"], []]
Example 2
words = ["eat","tea","tan","ate","nat","bat"]
queries = ["tae","bat","ant","t"]
-> [["eat","tea","ate"], ["bat"], ["tan","nat"], []]
Clarifications
- A word identical to the query counts as its anagram.
- Within each answer, words keep their order in
words; a word that appears twice inwordsappears twice in the answer. - A query with no anagrams gets an empty list.
Constraints: 1 ≤ words.length, queries.length ≤ 2·10^4; every word has 1 to 20 lowercase English letters; the answers hold at most 10^5 words in total.
Code runner format: two lines: words and queries as JSON arrays of strings. Implement findAnagrams(words, queries); the harness prints the list of answer lists.