#263 · Strings · Intermediate · 55 XP · about 8 min
The words "egg" and "add" have the same shape: a letter, then a different letter that is repeated. Two strings follow the same pattern when you can turn one into the other by swapping characters consistently: every copy of a character is replaced by the same character, and two different characters are never replaced by the same one.
Write same_pattern(a, b) that returns True if a and b follow the same pattern and False otherwise.
same_pattern('egg', 'add') # returns True same_pattern('paper', 'title') # returns True same_pattern('foo', 'bar') # returns False same_pattern('ab', 'aa') # returns False
In the last example both "a" and "b" would have to turn into "a", which is not allowed.
0 <= len(a), len(b) <= 100,000First solves only, ranked by stars and then time.