Coding practice
Practice real interview problems in your language.
Choose a problem, pick Python, C++, or JavaScript, and write a complete solution using the same constraints used in coding interviews.
Easy · Hash map
Two Sum
Given an integer array nums and an integer target, return the indices of the two numbers that add up to target. Each input has exactly one solution, and you may not use the same element twice.
Example
Input: nums = [2, 7, 11, 15], target = 9Output: [0, 1]Example
Input: nums = [3, 2, 4], target = 6Output: [1, 2]Interview hint
Store each number and its index as you scan. Look for target - current before storing the current number.
Constraints
- 2 <= nums.length <= 10,000
- -1,000,000,000 <= nums[i] <= 1,000,000,000
- Exactly one valid answer exists.
Runs the first example on the backend with a 5-second limit. File type: py