76. Two Items, Exact Budget (Two Sum)

Acceptance — 0 accepted 0 submissions

Medium
ArraysHashing
No companies listed
Divya has a gift voucher worth exactly target rupees. It must be spent fully on exactly two different items.

Given the prices, find the indices i and j (0-based, i < j) of the two items whose prices add up to target. Exactly one such pair exists.

Input Format
The first line has n.
The second line has n prices.
The third line has target.

Output Format
Print i and j separated by a space, with i < j.

Constraints
• 2 ≤ n ≤ 1000
• -10^4 ≤ price, target ≤ 10^4 (negative values are allowed to make it tricky)
• Exactly one valid pair exists.

Example 1

Input
4
2 7 11 15
9
Output
0 1

Explanation a[0] + a[1] = 2 + 7 = 9.

Example 2

Input
3
3 2 4
6
Output
1 2

Explanation a[1] + a[2] = 2 + 4 = 6. Using 3 twice is not allowed.

Example 3

Input
2
5 5
10
Output
0 1

Explanation Two different items can have the same price.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
0 1
No results yet
Run your code to test it against the sample cases.
Problem List