Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Two Sum

Python data engineering interview problem. Difficulty: beginner. Pattern: Hashing. About 10 minutes. Free to practice.

Return indices of two numbers that add to target. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement two_sum(nums: list, target: int) -> list returning 0-based indices [i, j] with i < j and nums[i] + nums[j] == target. Assume exactly one solution.

Requirements

  • Exactly one valid pair.

Constraints

  • Do not reuse the same index.

Examples

Input: two_sum([2, 7, 11, 15], 9) Output: [0, 1] 2 + 7 = 9.

Topics: lakebench, python, indices, hash map.

More Python interview questions · All interview problems · Learn data engineering

beginner

Two Sum

Interview-style drill: Return indices of two numbers that add to target.

Implement `two_sum(nums: list, target: int) -> list` returning 0-based indices `[i, j]` with i < j and nums[i] + nums[j] == target. Assume exactly one solution. Example: `[2, 7, 11, 15], 9` → `[0, 1]`. Keep the harness.