Pair With Target
easyYou're handed a list of item prices and a gift card worth exactly target. Find two different items whose prices add up to the full value of the card — no change left over.
Return the indices of the two items as a list [i, j] with i < j. Exactly one such pair is guaranteed to exist.
Example 1
in prices = [2, 7, 11, 15], target = 9
out [0, 1]
prices[0] + prices[1] = 2 + 7 = 9.
Example 2
in prices = [3, 2, 4], target = 6
out [1, 2]
Constraints
- · 2 <= len(prices) <= 10^4
- · -10^9 <= prices[i], target <= 10^9
- · exactly one valid pair exists
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.