"""
Exercise 2: Intersection of Two Arrays II (LeetCode 350)

Return the intersection where each element appears as many times as it
shows up in BOTH lists, sorted ascending. Count the smaller list with a dict.

  intersect([1, 2, 2, 1], [2, 2])       -> [2, 2]
  intersect([4, 9, 5], [9, 4, 9, 8, 4]) -> [4, 9]
"""

def intersect(nums1, nums2):
    # TODO
    return []


# --- self-check: do not modify below this line ---
cases = [([1, 2, 2, 1], [2, 2], [2, 2]), ([4, 9, 5], [9, 4, 9, 8, 4], [4, 9]), ([1], [2], []), ([3, 3, 3], [3, 3], [3, 3])]
ok = True
for a, b, want in cases:
    got = intersect(a, b)
    print(a, b, "->", got)
    ok = ok and got == want
print("PASS" if ok else "FAIL")
