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.
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
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.