Two keycard strings are isomorphic if the letters of the first can be consistently replaced to produce the second: every occurrence of a given letter in the first string must map to the same letter in the second string, no two distinct letters may map to the same letter, and the mapping must work in both directions. Strings of different lengths are never isomorphic.
Line 1: the first keycard string, of lowercase English letters. Line 2: the second keycard string, of lowercase English letters.
Print YES if the two strings are isomorphic, otherwise NO.
Example 1
Input
paper title
Expected
YES
Explanation
p->t, a->i, e->l, r->e is a consistent one-to-one mapping turning paper into title, so the answer is YES.
Example 2
Input
foo bar
Expected
NO
Explanation
The two o's would have to map to both a and r, which is inconsistent, so the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →