The Target Hunt
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L5
Problem
Given a list of integers and integer target, return all unique [x, y] pairs with x != y (from distinct indices) summing to target, each index used in at most one pair. Preserve discovery order (greedy: sweep left-to-right, for each x pick the smallest index y > x such that x+y = target and y is unclaimed). Return pairs as lists.
Summary
Pairs that hit a target. Every one of them.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.