Two Sum
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Runs in your browser
- Before starting
- Use a supported browser; initial dependencies may need internet.
- What it proves
- Run shows output; Test checks the authored cases, not every possible input.
- When finished
- Stop active runs when finished. No cloud infrastructure is provisioned by this exercise.
LEARN BY DOINGPut your intuition to work3 steps
Two Sum
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.Before you start
Browser lesson checks; review each requirement in Tests.
Catalog level: Easy · Estimated time: 15 min. Your prior experience can change the difficulty.
Sample case — your program reads stdin and prints to stdout.
Need a hand?
Start with a small test case. Hints progress from an idea to an explanation and, when requested, code.
Starter Given an array of integers and a target sum, find two numbers that add up to the target. Return the indices (0-based) of the two numbers.
Assume exactly one solution exists and you may not use the same element twice.
Example: nums=[2,7,11,15], target=9 → nums[0]+nums[1]=2+7=9 → Output: '0 1'
Input format
Line 1: n (array size). Line 2: n space-separated integers. Line 3: target.
Output format
Two space-separated indices (0-based, smaller first).
Constraints
2 ≤ n ≤ 10⁴, -10⁹ ≤ nums[i] ≤ 10⁹