<p>You are given two <strong>0-indexed</strong> strings <code>word1</code> and <code>word2</code>.</p>

<p>A <strong>move</strong> consists of choosing two indices <code>i</code> and <code>j</code> such that <code>0 &lt;= i &lt; word1.length</code> and <code>0 &lt;= j &lt; word2.length</code> and swapping <code>word1[i]</code> with <code>word2[j]</code>.</p>

<p>Return <code>true</code> <em>if it is possible to get the number of distinct characters in</em> <code>word1</code> <em>and</em> <code>word2</code> <em>to be equal with <strong>exactly one</strong> move. </em>Return <code>false</code> <em>otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> word1 = &quot;ac&quot;, word2 = &quot;b&quot;
<strong>Output:</strong> false
<strong>Explanation:</strong> Any pair of swaps would yield two distinct characters in the first string, and one in the second string.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> word1 = &quot;abcc&quot;, word2 = &quot;aab&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = &quot;abac&quot; and word2 = &quot;cab&quot;, which both have 3 distinct characters.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> word1 = &quot;abcde&quot;, word2 = &quot;fghij&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> Both resulting strings will have 5 distinct characters, regardless of which indices we swap.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= word1.length, word2.length &lt;= 10<sup>5</sup></code></li>
	<li><code>word1</code> and <code>word2</code> consist of only lowercase English letters.</li>
</ul>

class Solution(object):
    def isItPossible(self, word1, word2):
        #brute force algorithm #undergo every single char swap operation #each time, we check if the words have the same amount of distinct characters? #how can we check this? if we have a Counter dictionary, the length of this dictionary is going to give us that information. if at anytimes the length of our dictionaries is <=1, we are done. a swap was made that ensured a single move gives us our answer. we also have to make sure to properly swap #what is our swapping procedure going to look like? access the Counter dictionary for the respective letters we chose. Decrement its count, and app #this is going to be an o(n^2) algorithm. can we do better than this? #what if we make this an o(26 * 26) algorithm? meaning, we attempt every permutation of the alphabet. i.e a, a (well swapping the same character doesn't make sense), so we disclude swapping the same character. but swap a and b, a and c, a and d, and so on. this would be a length 26 for loop nested with a length 26 for loop, and way more efficient. and also, we will be checking if both the characters are in the words, and if they aren't, skip (because we can't remove/swap a char if its not in the word) #this revised algorithm gives us o(26 *26) time complexity essentially and o(n) space complexity vs o(n^2) time complexity and o(n) space complexity 
        s1 = "abcdefghijklmnopqrstuvwxyz" 
        s2 = "abcdefghijklmnopqrstuvwxyz" 
        w1_hashmap = Counter(word1)
        w2_hashmap = Counter(word2)
        
        for c1 in s1: 
            for c2 in s2: 
                if c1 not in w1_hashmap or c2 not in w2_hashmap:
                    continue
                print(w1_hashmap, w2_hashmap)
                w1_hashmap[c1]-=1
                if w1_hashmap[c1]==0:
                    del w1_hashmap[c1]
                w1_hashmap[c2]+=1
                w2_hashmap[c2]-=1
                if w2_hashmap[c2]==0:
                    del w2_hashmap[c2]
                w2_hashmap[c1]+=1
                if len(w1_hashmap)==len(w2_hashmap):
                    print(c1, c2)
                    return True
                w1_hashmap[c1]+=1
                w1_hashmap[c2]-=1
                if w1_hashmap[c2]==0:
                    del w1_hashmap[c2]
                w2_hashmap[c2]+=1
                w2_hashmap[c1]-=1
                if w2_hashmap[c1]==0:
                    del w2_hashmap[c1]
        return False
225