Two strings s and t are isomorphic if there is a one-to-one mapping between their characters that turns s into t: every occurrence of a character in s must map to the same character in t, and no two distinct characters of s may map to the same character of t.
Decide whether s and t are isomorphic.
Line 1: the string s.
Line 2: the string t.
Print YES if s and t are isomorphic, otherwise NO.
NO.Example 1
Input
egg add
Expected
YES
Explanation
Map e->a and g->d consistently; 'egg' becomes 'add'. The mapping is one-to-one, so YES.
Example 2
Input
foo bar
Expected
NO
Explanation
'o' would need to map to both 'a' and 'r', which is impossible, so 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 →