Isomorphic Strings - Problem
Given two strings s and t, determine if they are isomorphic.
Two strings s and t 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.
Input & Output
Example 1 — Basic Isomorphic Case
$
Input:
s = "egg", t = "add"
›
Output:
true
💡 Note:
Characters map consistently: 'e'→'a', 'g'→'d'. Pattern is preserved: first char different from next two, which are identical.
Example 2 — Non-Isomorphic Case
$
Input:
s = "foo", t = "bar"
›
Output:
false
💡 Note:
Character 'o' appears twice in s but maps to different characters in t: 'o'→'a' and 'o'→'r'. This violates isomorphic property.
Example 3 — Identity Mapping
$
Input:
s = "paper", t = "title"
›
Output:
true
💡 Note:
Valid mappings: 'p'→'t', 'a'→'i', 'p'→'t', 'e'→'l', 'r'→'e'. Each character maps consistently to exactly one other character.
Constraints
- 1 ≤ s.length ≤ 5 × 104
- t.length == s.length
- s and t consist of any valid ASCII character
Visualization
Tap to expand
Understanding the Visualization
1
Input Strings
Two strings s and t of equal length
2
Character Mapping
Check if characters can be mapped consistently
3
Validation Result
Return true if mapping is bijective and consistent
Key Takeaway
🎯 Key Insight: Two strings are isomorphic if they have identical character occurrence patterns and maintain consistent one-to-one mapping
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code