SQLDAXExcelPython
Leaderboard
Core PythonMedium20 points

Two numbers that add up to a target

Complete two_sum(numbers, target) so it returns the positions of the two numbers that add up to target, smaller position first. Exactly one pair exists. Aim to loop only once.

How your answer is tested

After your code, this runs and its result is checked:

result = [two_sum([2, 7, 11, 15], 9), two_sum([3, 2, 4], 6), two_sum([5, 1, 5], 10)]
Show solutionLifetime

Real Python running in your browser through Pyodide, with pandas available. Nothing you type is sent to a server unless you save a score.

Python
Loading editor…

Press Ctrl+Enter or Run to see the result here.