Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for One Switch Strings by arun_maiti
def switch_strings(line: str, result: str) -> bool:
if line == result:
return True
if len(line) != len(result):
return False
diff = [a + b for a, b in zip(line, result) if a != b]
return len(diff) == 2 and diff[0] == diff[1][::-1]
print("Example:")
print(switch_strings("btry", "byrt"))
# These "asserts" are used for self-checking
assert switch_strings("btry", "byrt") == True
assert switch_strings("boss", "boss") == True
assert switch_strings("solid", "disel") == False
assert switch_strings("false", "flaes") == False
assert switch_strings("true", "treu") == True
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 5, 2025
Comments: