Isomorphic Strings
easyTime: O(n)Space: O(1)
Signals to notice
check if two strings have same character mapping patternbidirectional mappingisomorphic check
Brute force first
Try all possible character mappings — O(26!). Impractical.
The key insight
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).
What must stay true
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'.
Easy way to go wrong
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).