2452. Words Within Two Edits of Dictionary Medium
1/**
2 * [2452] Words Within Two Edits of Dictionary
3 *
4 * You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.
5 * In one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.
6 * Return a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: queries = ["word","note","ants","wood"], dictionary = ["wood","joke","moat"]
11 * Output: ["word","note","wood"]
12 * Explanation:
13 * - Changing the 'r' in "word" to 'o' allows it to equal the dictionary word "wood".
14 * - Changing the 'n' to 'j' and the 't' to 'k' in "note" changes it to "joke".
15 * - It would take more than 2 edits for "ants" to equal a dictionary word.
16 * - "wood" can remain unchanged (0 edits) and match the corresponding dictionary word.
17 * Thus, we return ["word","note","wood"].
18 *
19 * <strong class="example">Example 2:
20 *
21 * Input: queries = ["yes"], dictionary = ["not"]
22 * Output: []
23 * Explanation:
24 * Applying any two edits to "yes" cannot make it equal to "not". Thus, we return an empty array.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= queries.length, dictionary.length <= 100
30 * n == queries[i].length == dictionary[j].length
31 * 1 <= n <= 100
32 * All queries[i] and dictionary[j] are composed of lowercase English letters.
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/words-within-two-edits-of-dictionary/
38// discuss: https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn two_edit_words(queries: Vec<String>, dictionary: Vec<String>) -> Vec<String> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2452() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.