java.lang.Object
g2401_2500.s2452_words_within_two_edits_of_dictionary.Solution

public class Solution extends Object
2452 - Words Within Two Edits of Dictionary.<p>Medium</p> <p>You are given two string arrays, <code>queries</code> and <code>dictionary</code>. All words in each array comprise of lowercase English letters and have the same length.</p> <p>In one <strong>edit</strong> you can take a word from <code>queries</code>, and change any letter in it to any other letter. Find all words from <code>queries</code> that, after a <strong>maximum</strong> of two edits, equal some word from <code>dictionary</code>.</p> <p>Return <em>a list of all words from</em> <code>queries</code><em>,</em> <em>that match with some word from</em> <code>dictionary</code> <em>after a maximum of <strong>two edits</strong></em>. Return the words in the <strong>same order</strong> they appear in <code>queries</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> queries = [&ldquo;word&rdquo;,&ldquo;note&rdquo;,&ldquo;ants&rdquo;,&ldquo;wood&rdquo;], dictionary = [&ldquo;wood&rdquo;,&ldquo;joke&rdquo;,&ldquo;moat&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;word&rdquo;,&ldquo;note&rdquo;,&ldquo;wood&rdquo;]</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>Changing the &lsquo;r&rsquo; in &ldquo;word&rdquo; to &lsquo;o&rsquo; allows it to equal the dictionary word &ldquo;wood&rdquo;.</p> </li> <li> <p>Changing the &lsquo;n&rsquo; to &lsquo;j&rsquo; and the &lsquo;t&rsquo; to &lsquo;k&rsquo; in &ldquo;note&rdquo; changes it to &ldquo;joke&rdquo;.</p> </li> <li> <p>It would take more than 2 edits for &ldquo;ants&rdquo; to equal a dictionary word.</p> </li> <li> <p>&ldquo;wood&rdquo; can remain unchanged (0 edits) and match the corresponding dictionary word.</p> </li> </ul> <p>Thus, we return [&ldquo;word&rdquo;,&ldquo;note&rdquo;,&ldquo;wood&rdquo;].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> queries = [&ldquo;yes&rdquo;], dictionary = [&ldquo;not&rdquo;]</p> <p><strong>Output:</strong> []</p> <p><strong>Explanation:</strong></p> <p>Applying any two edits to &ldquo;yes&rdquo; cannot make it equal to &ldquo;not&rdquo;. Thus, we return an empty array.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= queries.length, dictionary.length <= 100</code></li> <li><code>n == queries[i].length == dictionary[j].length</code></li> <li><code>1 <= n <= 100</code></li> <li>All <code>queries[i]</code> and <code>dictionary[j]</code> are composed of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details