Tasks /
TypeScript /
Two sum — TypeScript
Statement
medium
Two sum — TypeScript
Implement `twoSum(nums, target)`: return the indices of two numbers that add up
to `target`. Each number may be used once; indices are returned in ascending
order.
If there is no solution, throw an `Error`.
TypeScript · Vitest
AI mentor
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and ask
Hints
1 of 3 unlocked · attempts: 0
Hint 1
Remember which numbers you have already seen and at which index during a single
pass. For the current number you need `target - nums[i]`.
Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts