Find the intersection of two sets $A = \\{a0, a1, ..., a{n-1}\\}$ and $B = \\{b0, b1,…
- User
Find the intersection of two sets and .
Assistant
python# Read input n = int(input()) A = list(map(int, input().split())) m = int(input()) B = list(map(int, input().split())) i = j = 0 result = [] while i < n and j < m: if A[i] == B[j]: result.append(A[i]) i += 1 j += 1 elif A[i] < B[j]: i += 1 else: j += 1 # Print each element in the result for num in result: print(num)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.