Codey

Improve your coding through problem solving

Practise algorithms and data structures, test your solutions in the browser and track your progress over time.

two-sum.py

def two_sum(nums, target):

seen = {}

for index, value in enumerate(nums):

difference = target - value

if difference in seen:

return [seen[difference], index]

seen[value] = index

Accepted

25 / 25 test cases passed

150+

Coding problems

4

Supported languages

Instant

Test feedback

How Codey works

From problem to accepted solution

Choose a challenge, test your approach, then submit your solution and keep track of what you have solved.

01

Choose a problem

Pick from problems across different topics and difficulty levels, then work through the description and examples.

Two Sum

Arrays · Hash Table

Easy

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to the target.

nums = [2, 7, 11, 15]

target = 9

Test cases

Input

nums = [2, 7, 11, 15]
target = 9

Result

Passed

Output

[0, 1]

02

Write and test your solution

Write code directly in the browser and check it against provided or custom test cases before submitting.

03

Submit and track your progress

Submit against the larger number of test cases, revisit previous attempts and see your progress build over time.

Accepted

25 / 25 test cases passed

Problems solved

47

Submissions

86

Acceptance rate

54.7%

Ready to solve your first problem?

Create an account to save submissions, revisit your solutions and track your progress.

Log in or sign up