Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First appearence solution in Clear category for Surjection Strings by Dm_Ch
def isometric_strings(str1: str, str2: str) -> bool:
if len(str1) != len(str2):
return False
# Main idea: letters with the same indices can be different in both words
# but all of their copies should appear in the same indices for both words.
# So need to check index of letter's first appearence for all letters.
for x in range(1, len(str1)):
if str1.find(str1[x]) != str2.find(str2[x]):
return False
return True
if __name__ == '__main__':
print("Example:")
print(isometric_strings('add', 'egg'))
# These "asserts" are used for self-checking and not for an auto-testing
assert isometric_strings('add', 'egg') == True
assert isometric_strings('foo', 'bar') == False
assert isometric_strings('', '') == True
assert isometric_strings('all', 'all') == True
print("Coding complete? Click 'Check' to earn cool rewards!")
April 9, 2021