easy +8 pts

Is Subset of Another List

Check whether every element of one list appears in another list.

Write a function `is_subset(sub, full)` that takes two lists, `sub` and `full`, and returns `True` if every element of `sub` is present in `full`. The lists may contain duplicates; duplicates in `sub` do not need to be matched by duplicates in `full` — membership is the only requirement. The order of elements does not matter. Assume both lists contain only hashable elements (e.g., integers or strings).

Constraints

0 <= len(sub) <= 10^5 0 <= len(full) <= 10^5 Elements are hashable. Time complexity should be O(len(sub) + len(full)) on average. Space complexity O(len(full)).

Example

['>>> is_subset([1, 2], [1, 2, 3])', 'True', '>>> is_subset([1, 2, 2], [1, 2])', 'True', '>>> is_subset([3], [1, 2])', 'False', '>>> is_subset([], [1, 2])', 'True']
8 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Consider converting the `full` list to a set for O(1) lookups.
A list is a subset if every item in it is a member of the set.
Remember that an empty list is a subset of any list.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.