/349. Intersection of Two Integer Arrays

349. Intersection of Two Integer Arrays

Easy
Arrays77.6% acceptance

Given two integer lists, list_a and list_b, return a list containing the unique elements that appear in both lists. The order of elements in the output list does not matter.

Example 1

Input: list_a = [7, 3, 5, 7], list_b = [5, 7, 7]

Output: [5, 7]

Explanation: Both 5 and 7 appear in both lists. Output order does not matter.

Example 2

Input: list_a = [10, 20, 30], list_b = [40, 50, 60]

Output: []

Explanation: No common elements between the lists.

Example 3

Input: list_a = [2, 2, 2], list_b = [2, 2]

Output: [2]

Explanation: 2 is the only common element, returned uniquely.

Constraints

  • 1 <= len(list_a) <= 1000
  • 1 <= len(list_b) <= 1000
  • 0 <= element in list_a <= 1000
  • 0 <= element in list_b <= 1000
Python (current runtime)

Case 1

Input: list_a = [1, 4, 6, 8], list_b = [6, 8, 9, 10]

Expected: [6, 8]

Case 2

Input: list_a = [0, 1, 2, 3], list_b = [3, 4, 5, 6]

Expected: [3]

Case 3

Input: list_a = [1000], list_b = [1000, 999]

Expected: [1000]

Case 4

Input: list_a = [11, 22, 33, 44], list_b = [22, 44, 55, 66]

Expected: [22, 44]

Case 5

Input: list_a = [5, 5, 5, 5], list_b = [5]

Expected: [5]