import pytest def findIntersection(arr): unique = list() duplicates = [] for string in arr: for char in string.split(','): if int("".join(char)) in unique: duplicates.append(int("".join(char))) else: unique.append(int("".join(char))) return duplicates @pytest.mark.parametrize( ("arr_s", "expected"), (["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"], [1, 4, 13]), ) def test(arr_s, expected): assert findIntersection(arr_s) == expected if __name__ == "__main__": x = ["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"] print(findIntersection(x))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: A common coding interview question
For further actions, you may consider blocking this person and/or reporting abuse