You're given two string arrays: queries and dictionary. All words in both arrays consist of lowercase English letters and have the same length.
In one edit operation, you can take any word from queries and change exactly one letter to any other letter. Your task is to find all words from queries that can be transformed to match some word in the dictionary using at most two edits.
Goal: Return a list of all words from queries that match with some dictionary word after a maximum of two edits. Preserve the original order from queries.
Example: If queries = ["word", "note"] and dictionary = ["world", "note"], then "word" needs 1 edit to become "world", and "note" needs 0 edits (exact match).
Input & Output
Visualization
Time & Space Complexity
n queries ร m dictionary words ร k character comparisons, but with better constants
Space for dictionary hash set containing m words
Constraints
- 1 โค queries.length, dictionary.length โค 1000
- queries[i].length = dictionary[j].length for all valid i, j
- 1 โค queries[i].length โค 100
- All queries[i] and dictionary[j] consist of lowercase English letters only