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
length
. -
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
What is the output, if the following strings are given as an input?
string1 = “ACAB”
string2 = “XCXY”
True
False
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.
Try it yourself
Implement your solution in the following coding playground.
export function isIsomorphic(string1, string2){// Replace this placeholder return statement with your codereturn false}