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
pythonimport sys def main(): # Read input n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) m = int(sys.stdin.readline()) b = list(map(int, sys.stdin.readline().split())) # Two pointers approach 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 the result for num in result: print(num) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.