Company: Hitachi - Codility

Difficulty: medium

Problem Statement

Implement an autocorrect function that finds all anagrams of a given search query. Two strings are anagrams if they contain the same characters with the same frequencies. You are given: An array words of length n An array queries of length q For each query string: Return all words in words that are anagrams of the query Sort the matching words in alphabetical order Collect the results into an array (one list per query) Return a list of all these per-query results. Example Suppose words = ["duel", "speed", "dule", "cars"] and queries = ["spede", "deul"] . Output: [["speed"], ["duel", "dule"]] . Explanation: For "spede", the only anagram is "speed" For "deul", the anagrams are "duel" and "dule" Constraints 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 words. All strings consist of lowercase English letters only.

More Hitachi - Codility OA questionsInterview experiences