Two strings s and t are isomorphic if the characters of s can be replaced to get t while preserving order.
Every occurrence of a character must map to the same character, and no two characters may map to the same character. A character may map to itself.
Input / output
s: string, t: stringbooleanExamples
s = "egg", t = "add" returns true (e->a, g->d).s = "foo", t = "bar" returns false (o would map to both a and r).s = "paper", t = "title" returns true.Constraints
0 <= s.length == t.length <= 50000s and t consist of any Unicode characters (ASCII in the tests).Edge cases
"badc" and "baba" are not isomorphic.Target complexity
O(n) time and O(1) extra space (bounded alphabet).Hints
s to t and one from t to s.Follow-up How does this differ from checking whether the two strings follow the same repetition pattern (word pattern)?