String Mapping
Start Timer
0:00:00
Given two strings, string1 and string2, write a function str_map to determine if there exists a one-to-one correspondence (bijection) between the characters of string1 and string2.
For the two strings, our correspondence must be between characters in the same position/index.
Example 1:
Input:
string1 = 'qwe'
string2 = 'asd'
string_map(string1, string2) == True
# q = a, w = s, and e = d
Example 2:
Input:
string1 = 'donut'
string2 = 'fatty'
string_map(string1, string2) == False
# cannot map two distinct characters to two equal characters
Example 3:
Input:
string1 = 'enemy'
string2 = 'enemy'
string_map(string1, string2) == True
# there exists a one-to-one correspondence between equivalent strings
Example 4:
Input:
string1 = 'enemy'
string2 = 'ymene'
string_map(string1, string2) == False
# since our correspondence must be between characters of the same index, this case returns 'False' as we must map e = y AND e = e
.
.
.
.
.
.
.
.
.
Comments