A HACKERBREWERY ORIGINAL
A perfect pair
EasyArraysHash maps
The brewery has a shelf of numbered coffee bags. Find two different bags whose numbers add up to the target. Return their zero-based indices in ascending order. There is exactly one matching pair, and you cannot use the same bag twice.
Example 1
INPUT
[3,8,4,6], 10OUTPUT[2,3]The bags at indices 2 and 3 contain 4 and 6. Together, they make 10.
Example 2
INPUT
[5,5], 10OUTPUT[0,1]Two bags can have the same number, but they must have different indices.
Keep in mind
- 2 ≤ numbers.length ≤ 10,000
- Each number and target is an integer between −100,000 and 100,000.
- Exactly one pair exists.
Draft saved on this browserSpaces: 2 UTF-8
INPUT
[3,8,4,6], 10EXPECTED OUTPUT
[2,3]Public samples only. These checks do not award ranked points.