Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-046

Intersection of Two Arrays

Problem

Compute the intersection of two arrays, returning each common value once.

Convert both inputs to sets and take their intersection.

Return the common values sorted in ascending order.

Hint

Python sets support intersection with the & operator.

Test cases

case 1
in: [[1,2,2,1],[2,2]]
expected: [2]
case 2
in: [[4,9,5],[9,4,9,8,4]]
expected: [4,9]
case 3
in: [[],[1]]
expected: []
case 4
in: [[1,2],[3,4]]
expected: []
Starter codePython
def array_intersection(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor