Two Sum
Given a list of integers and a target, return the indices of the two numbers that add up to the target.
You may assume there is exactly one pair. Each element can be used only once.
nums = [2, 7, 11, 15]
target = 9
output = [0, 1]2 + 7 = 9
Meet an opponent. Solve the same problem. Keep a record of every round.
Given a list of integers and a target, return the indices of the two numbers that add up to the target.
You may assume there is exactly one pair. Each element can be used only once.
nums = [2, 7, 11, 15]
target = 9
output = [0, 1]2 + 7 = 9
def two_sum(nums, target): seen = {} for i, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return []Expected [0, 1] · Output [0, 1]Write Python and check public examples in a focused workspace.
Choose a unique username, an avatar color, and your own bio.
Revisit completed matches and the problems you played.
Casual beta. Verified ranked play is coming later. How CodeClash works
Create your account, choose a unique username, and find your first opponent.
Your first sign-in creates an account. Already played? Use the same provider to keep your existing progress.
By continuing, you agree to our Terms. See our Privacy notice for how we handle your data.