easy +10 pts

Disjoint Set Check

Determine if two lists share no common elements using set operations.

Write a function `are_disjoint(list1, list2)` that takes two lists and returns `True` if they have no elements in common, and `False` otherwise. The elements can be of any hashable type (e.g., integers, strings). The lists may be empty. The order of elements does not matter. Use set operations for efficiency.

Constraints

The lists may contain up to 10^5 elements each. Elements are hashable. Time complexity should be O(n+m) on average, where n and m are the lengths of the lists.

Example

>>> are_disjoint([1,2,3], [4,5,6])
True
>>> are_disjoint([1,2,3], [3,4,5])
False
>>> are_disjoint([], [1,2,3])
True
>>> are_disjoint([], [])
True
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Convert one list to a set to allow O(1) membership tests.
Loop through the other list and check if any element is in the set.
Return False as soon as a common element is found.
If the loop completes without finding a common element, return True.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.