# Given two lists a = [1, 2, 3, 4, 5] and b = [3, 4, 5, 6, 7], find common elements in O(n + m) using

Canonical URL: <https://datadriven.io/problems/given-two-lists-a-1-2-3-4-5-and-b-3-4-5-6-7-fbb8b216>

Domain: Python · Difficulty: medium

## Problem

Given two lists a = [1, 2, 3, 4, 5] and b = [3, 4, 5, 6, 7], find common elements in O(n + m) using a set for a. Print the sorted list of common elements.

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/given-two-lists-a-1-2-3-4-5-and-b-3-4-5-6-7-fbb8b216)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.