<p>Given two strings <code>s</code> and <code>t</code>, <em>determine if they are isomorphic</em>.</p>

<p>Two strings <code>s</code> and <code>t</code> are isomorphic if the characters in <code>s</code> can be replaced to get <code>t</code>.</p>

<p>All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.</p>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;egg&quot;, t = &quot;add&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>

<p><strong>Explanation:</strong></p>

<p>The strings <code>s</code> and <code>t</code> can be made identical by:</p>

<ul>
	<li>Mapping <code>&#39;e&#39;</code> to <code>&#39;a&#39;</code>.</li>
	<li>Mapping <code>&#39;g&#39;</code> to <code>&#39;d&#39;</code>.</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;foo&quot;, t = &quot;bar&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">false</span></p>

<p><strong>Explanation:</strong></p>

<p>The strings <code>s</code> and <code>t</code> can not be made identical as <code>&#39;o&#39;</code> needs to be mapped to both <code>&#39;a&#39;</code> and <code>&#39;r&#39;</code>.</p>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;paper&quot;, t = &quot;title&quot;</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>
</div>

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

<ul>
	<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
	<li><code>t.length == s.length</code></li>
	<li><code>s</code> and <code>t</code> consist of any valid ascii character.</li>
</ul>

#include <unordered_map>
class Solution {
public:
    bool check(string str1, string str2){
        // Unordered map to store the
        // Hash value for each string
        unordered_map<char, int> fre;
    
        int size1 = str1.size();
        int size2 = str2.size();
    
        // Check whether size equals or not,
        // if not then isomorphism
        // can't be achieved
        if (size1 != size2)
            return false;
    
        for (int i = 0; i < size1; i++) {
    
            // Check whether current character
            // already hashed or not
            if (fre.find(str1[i]) == fre.end()) {
    
                // If not then assign
                // hash value to it
                fre[str1[i]] = str1[i] - str2[i];
            }
    
            // If already hashed then compare
            // with its current hashed value
            else if (fre[str1[i]]
                    != (str1[i] - str2[i])) {
                return false;
            }
        }
        return true;
    }
    bool isIsomorphic(string s, string t) {
        
        // int n = s.size();
        // int m = t.size();

        // if(n!=m)
        //     return false;

        // unordered_map<char, char> mpp;

        // for(int i=0; i<n; i++){
        //     if(mpp.find(s[i]) == mpp.end()){
        //         mpp[s[i]] = t[i];
        //     }
        //     if(mpp.find(s[i]) == mpp.end()){
        //         return false;
        //     }
        //     else if(mpp[s[i]] != t[i])
        //         return false;
        // }
        // return true;

        // Method 2 
        return check(s,t) && check(t,s);
    }
};
9900