Peter Parker And Strings

0

0 votes
Problem

After being exposed to the whole world Peter Parker asks Dr. Strange for help. Dr. Strange tells him that there is a spell that can make everyone forget that Peter Parker is Spiderman. Despite being warned by Wong, Dr. Strange decides to cast the spell but Peter Parker disrupts the spell and opens a portal from other universes.

People who know that Peter Parker is Spiderman from other universes start to come through the portal. Peter Parker wants to undo the spell and ask Dr. Strange again for his help, for this Dr. Strange gives him a task in which he gives two strings and wants to know that two strings are isomorphic or not i.e. if there is one to one mapping for every possible character of the first string to the second string. All occurrences of every character of first string should map to the same character.

No two characters may map to the same character, but a character may map to itself.

For example strings “accd” and “puud” are isomorphic where a is mapped to p, c is mapped to u, and d is mapped to d. But strings “addk” and “apqs” are not because there is no one-to-one mapping possible.

Now Peter Parker is busy fighting villains. So he asked you to solve this task and help him.

Print 1 if both strings are isomorphic otherwise print 0.

INPUT FORMAT

The first line contains string str1

The next line contains string str2.

OUTPUT FORMAT

Output 1 if strings are isomorphic to each other otherwise output 0.

CONSTRAINTS

1 <= str1.length <= 10^5

1 <= str2.length <= 10^5

Both str1 and str2 contain only lower English characters.

 

Sample Input
addsea
nllken
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Given strings are isomorphic as characters of str1 can be replaced to obtain str2

a is mapped to n

d is mapped to l

s is mapped to k

e is mapped to e

Editor Image

?