Skip to content
BytePatterns

Consistent Renaming Check

EasyHash Tables#hash-map#bijection~20m

Problem

Two pieces of text have the same shape if one can be turned into the other by renaming characters. A renaming must be consistent in both directions: every occurrence of a character maps to the same replacement, and no two different characters may share a replacement. Decide whether such a renaming exists.

Examples

Input:  a = "egg", b = "add"
Output: True
Why:    e becomes a and g becomes d, consistently
Input:  a = "foo", b = "bar"
Output: False
Why:    o would have to become both a and r
Input:  a = "ab", b = "aa"
Output: False
Why:    edge case, two characters may not collapse onto the same replacement

Hints

0 / 3

Stuck on the idea rather than the code? Hash Table Basics covers it.