Shared Values

Sometimes you need to quickly find what two datasets have in common, such as products available in two warehouses. Given two arrays a and b, return their intersection: the unique values that appear in both arrays. The result should be sorted in ascending order.

Примеры

Ввод
[1, 2, 2, 1], [2, 2]
Вывод
[2]
Ввод
[4, 9, 5], [9, 4, 9, 8, 4]
Вывод
[4, 9]
Ввод
[1, 2, 3], [4, 5, 6]
Вывод
[]

Нужно реализовать

def intersection(a, b):

Теги

arraysethashmap
PostgreSQLv16

Šeit parādīsies koda izpildes rezultāts

Visible tests
1
Input
[1,2,2,1], [2,2]
Expected[2]
2
Input
[4,9,5], [9,4,9,8,4]
Expected[4,9]
3
Input
[1,2,3], [4,5,6]
Expected[]
4
Input
[], [1,2]
Expected[]
5
Input
[3,1,2], [2,3,1]
Expected[1,2,3]
6
Input
[2,2,1,1], [2,2,2,2]
Expected[2]
Focus radio
Paused · SomaFM · Fluid