Two Sum Easy
Problem Statement
Given an array of integers `nums` and an integer `target`, return the indices of the two numbers such that they add up to `target`.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
Input Format
The first line contains two integers `n` (the size of the array) and `target`.
The second line contains `n` space-separated integers representing the array.
Output Format
Print two space-separated integers representing the indices (0-indexed) of the two numbers that add up to target.
Constraints
- 2 <= nums.length <= 10^4
- -10^9 <= nums[i] <= 10^9
- -10^9 <= target <= 10^9
- Only one valid answer exists.
Examples
Example 1
Input
4 9
2 7 11 15
Output
0 1
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2
Input
3 6
3 2 4
Output
1 2
Explanation: nums[1] + nums[2] == 6
Your Submissions
No submissions yet
Sign in to Submit
Create an account or log in to submit your solution and track your progress.