Problem · Hash Table
Isomorphic Strings
Learn this problemProblem statement
Given two strings s and t, determine whether they are isomorphic.
The strings are isomorphic when every character in s can be replaced consistently to produce t without changing character positions. Every occurrence of one character must map to the same character, and two different characters from s cannot map to the same character in t. A character may map to itself.
Function
isIsomorphic(s: String, t: String) → booleanExamples
Example 1
s = "egg"t = "add"return = trueMap 'e' to 'a' and 'g' to 'd'. Applying those substitutions consistently produces t.
Example 2
s = "f11"t = "b23"return = falseThe character '1' would need to map to both '2' and '3', so no consistent mapping exists.
Example 3
s = "paper"t = "title"return = trueThe repeated-character pattern is identical in both strings, and each character has one distinct position-preserving mapping.
Constraints
1 <= s.length <= 5 * 10^4t.length == s.lengthsandtcontain valid ASCII characters.