Hi everyone.
Let's do this question.
Given two strings, S and T, determine if they are isomorphic.
Two strings S and T are isomorphic if the characters in S can be replaced to get T, all occurrences
of a character must be replaced with another character while preserving the order of characters.
No two characters may map to the same character, but a character may map to itself.
S and T consist of any valid Ascii character.
All right, now let's take a look at this.
Now we have S over here and we have T over here.
So let's try to understand this question using these two examples.
Now it says that we should get from S to T by replacing every character in S with another particular
character.
So for example over here we replace a with r.
Now you can see that over here also we replace a with R right.
And b is replaced with I, c is replaced with f, u is replaced with g and s is replaced with s.
So this over here is true.
So we can understand that these two strings over here's and T are isomorphic.
Now let's look at a case where they are not isomorphic.
Now over here we can see that we have mapped A to P.
But in this case again A is mapped to R right.
So the mapping is not unique.
Therefore this is false.
So S and R over here these two strings are not isomorphic.
So that is what it means when we say that two strings are isomorphic.
All right.
So a string a character in string S has to map to some other character or itself in T.
Now if we take a to R then you cannot have.
You also map to R.
So that is mentioned also over here no two characters may map to the same character.
So we have understood what is being tested over here.
So we have to write a function and s and t will be given to us.
We have to check whether they are isomorphic or not, and if they are isomorphic we have to return true.
And if they are not isomorphic, we have to return false.
So that's the question.
Now remember in the interview, if you have any questions, ensure that you ask sufficient clarifying
questions so that you are clear that you have understood the question as the interviewer has stated
it to you.
Now let's proceed and write some test cases over here.
Now let's say A is a, b, a, b, r, and t is e o e o o.
Now over here you can see that b is mapped to O.
But r is also mapped to O.
And this is a violation of the condition which we just now discussed.
Right.
So if this these are the two strings given to us then we would have to return false.
Now let's look at another test case.
And again over here it's false because two characters cannot map to the same character.
Right.
And that's what's happening over here B is mapped to O.
And R is also mapped to O.
Now let's look at another test case.
Let's say the strings given to us are a, b, a, b, r and p q r q o.
Now over here we can see that a is mapped to p over here.
But then again A is mapped to R over here which is not allowed right.
It should be unique if A is mapped to P over here.
Over here also A should have mapped to P right.
So again because of this reason, if these are the two strings given to us we would have returned false.
Right now B is mapped to Q which is correct.
And over here also b is mapped to q.
That is correct.
And r is mapped to O.
That is also not an issue over here.
If we had P then we would have identified this as true.
All right.
Now what.
Now let's take another example.
Let's say we have S as green and t as ABCd.
Now over here g is mapped to a all right.
And r is mapped to B, e is mapped to c, E is mapped to c.
That's true.
And n is mapped to D.
So yes over here we have true.
Now what would be the case if we have s as let's say a b, c.
And let's say we have t as p and q right.
So in this case we would have to return false.
Why is that so.
Because C is not mapped to anything.
But C has to be mapped to something right.
It has to either map to C itself or another character.
Right.
So in this case also we would have to return false.
So we have understood the question and we have written out test cases.
So we have a good understanding of the question.
In the next video let's try to think about how we can solve this question.