easy +10 pts

Intersection of Two Lists

Return the unique common elements from two lists in sorted order.

Write a function `intersection_of_lists(list1, list2)` that takes two lists of integers and returns a new list containing the unique integers that appear in both lists, sorted in ascending order. The result should contain each common integer only once, even if it appears multiple times in either list. The original lists should not be modified. If there is no common element, return an empty list.

Constraints

- Lists can be empty. - Elements are integers. - The length of each list is between 0 and 10^5. - Expected time complexity O((n+m) log(n+m)) or O(n+m) with extra space, but sorting output is required.

Example

>>> intersection_of_lists([1,2,2,3,4], [2,2,3,5])
[2, 3]
>>> intersection_of_lists([], [1,2])
[]
>>> intersection_of_lists([1,2,3], [4,5])
[]
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Consider converting lists to sets to eliminate duplicates and find common elements.
Remember to sort the resulting set to match the required order.
Empty input should return an empty list.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.