diff --git a/Dictionaries and Hashmaps/TwoStrings.py b/Dictionaries and Hashmaps/TwoStrings.py index 6f1a6f1..52d682f 100644 --- a/Dictionaries and Hashmaps/TwoStrings.py +++ b/Dictionaries and Hashmaps/TwoStrings.py @@ -8,7 +8,15 @@ # Complete the twoStrings function below. def twoStrings(s1, s2): - return 'YES' if any(i in s2 for i in s1 ) else 'NO' + # Convert both strings to sets to obtain unique characters + set_s1 = set(s1) + set_s2 = set(s2) + + # Compute the intersection of the two sets + intersection = set_s1 & set_s2 + + # Return 'YES' if the intersection is not empty, otherwise 'NO' + return 'YES' if intersection else 'NO' if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w')