easyHash TableArrays & Hashing

Isomorphic Strings

easyTime: O(n)Space: O(1)

Recognize the pattern

check if two strings have same character mapping patternbidirectional mappingisomorphic check

Brute force idea

Try all possible character mappings — O(26!). Impractical.

Better approach

Two hash maps: s→t and t→s. For each position, check that both mappings are consistent. If s[i] maps to a different t character or vice versa, not isomorphic. O(n).

Key invariant

The mapping must be bidirectional — s[i]→t[i] AND t[i]→s[i] must both be consistent. A one-way check misses cases like 'ab'→'aa'.

Watch out for

Only checking one direction — 'ab' maps to 'aa' is consistent s→t but not t→s (both a and b map to a, but a maps to both a and b).

Arrays & Hashing Pattern