...

/

Isomorphic Strings

Isomorphic Strings

Try to solve the Isomorphic Strings problem.

Statement

Given two strings, check whether two strings are isomorphic to each other or not.  Two strings are isomorphic if a fixed mapping exists from the characters of one string to the characters of the other string. For example, if there are two instances of the character "a"  in the first string, both these instances should be converted to another character (which could also remain the same character if "a" is mapped to itself) in the second string. This converted character should remain the same in both positions of the second string since there is a fixed mapping from the character "a" in the first string to the converted character in the second string.

Note: Two different characters cannot map to the same character. Furthermore, all the instances of a character must be replaced with another character while protecting the order of characters.

Constraints:

  • Both the strings consist of valid ASCII characters.

  • The length of the string is 00 \leq length \leq 10410^{4}.

  • The length of both strings is the same.

Examples

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check that you’re solving the correct problem:

Isomorphic strings

1.

What is the output, if the following strings are given as an input?

string1 = “ACAB”

string2 = “XCXY”

A.

True

B.

False


1 / 4

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4

Try it yourself

Implement your solution in the following coding playground:

Python
usercode > main.py
def is_isomorphic(string1, string2):
# Replace this placeholder return statement with your code
return False
Isomorphic Strings

Access this course and 1200+ top-rated courses and projects.