Intersection and union of small sets
Input
set_intersection_union({1, 2, 3}, {2, 3, 4})
Output
([2, 3], [1, 2, 3, 4])
Intersection is {2,3} and union is {1,2,3,4}, returned as sorted lists.
Full lesson preview
Compute the intersection and union of two collections, returning sorted lists for deterministic output.
Problem statement
Task
Examples
Input
set_intersection_union({1, 2, 3}, {2, 3, 4})
Output
([2, 3], [1, 2, 3, 4])
Intersection is {2,3} and union is {1,2,3,4}, returned as sorted lists.
Input format
Output format
Constraints
Samples
Input
set_intersection_union([3, 1, 2], [2, 4])
Output
([2], [1, 2, 3, 4])
Duplicates removed; intersection [2], union [1,2,3,4].