Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
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.
Example 1
Input
egg add
Output
true
Explanation
e → a and g → d. Every character maps consistently, so the strings are isomorphic.
Example 2
Input
foo bar
Output
false
Explanation
The character 'o' would need to map to both 'a' and 'r', which is not allowed.
Constraints
Hints:
Hint 1
Use a hash map to store the mapping from characters in s to characters in t.
Hint 2
Maintain another hash map (or set) to ensure that two different characters in s do not map to the same character in t.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 6, 2026
Last updated
Aug 7, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output