Facebook Pixel

Isomorphic String

Given two strings, determine if they are isomorphic. Two strings are "isomorphic" if each unique character from the first string can be replaced to match the second string, without changing the ordering of the characters.

Different characters must map to different characters, but a character can map to itself.

Input & Output
Input
str_1 — the first string.
str_2 — the second string.
Output
Whether if these two strings are isomorphic.
Example
Input
str_1 = "egg"
str_2 = "all"
Output
true
Explanation

"e" can be replaced with "a" and "g" can be replaced with "l". Therefore, the strings are isomorphic.

Example
Input
str_1 = "wow"
str_2 = "aaa"
Output
false
Explanation

"w" and "o" both maps to "a", which makes them not isomorphic.

Constraints
  • 1 <= len(str_1), len(str_2) <= 5 * 10^4
  • The strings are case sensitive and consists of valid ASCII characters.

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro