dsa · easy

Isomorphic Strings

s and t have the same length. They are isomorphic when you can replace every character of s to obtain t, with two rules: each character maps to exactly one character, and no two characters map to the same character. A character may map to itself.

Arguments

Example

s = "egg", t = "add": e→a, g→dtrue.

s = "foo", t = "bar": o would have to become both a and rfalse.

s = "paper", t = "title"true.

Constraints

1 <= s.length <= 5 * 10^4 t.length == s.length s and t contain lowercase English letters. Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
'egg'
'add'

Expected:
true

Example 2

Input:
'foo'
'bar'

Expected:
false

Example 3

Input:
'paper'
'title'

Expected:
true

Open in the Dojo editor