Easy · Bidirectional Mapping
Understand → Visualise → Practice.
Return whether characters of the first string can be replaced one-to-one to produce the second string.
The mapping must be a bijection: each character of a maps to one character of b, and no two characters of a map to the same character of b. Track both directions.
Different lengths can never be isomorphic.
For each pair (x, y), x must map to y and y must map back to x; record the pair if it is new.
Any conflict means false; otherwise true.
O(n) time and O(1) space for a fixed alphabet.
Checking only a → b accepts "ab" and "cc", where two letters wrongly map to the same one.
Read the full guide first: Hash Maps and Hash Sets.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.