Matching Hedge Pairs
Problem
You are a risk analyst at a hedge fund reviewing a portfolio of n trading positions. Each position has a daily P&L (profit and loss) value. Your compliance team needs you to identify exactly two positions whose combined P&L equals a specific hedge target — this pair will be used to construct a delta-neutral hedge.
Given the array of P&L values and a hedge target, return the indices (0-indexed) of the two positions that sum to the target. Return the smaller index first.
It is guaranteed that exactly one valid pair exists.
Input Format
- First line: two integers
n(number of positions) andtarget(the hedge target sum). - Second line:
nspace-separated integers representing P&L values.
Output Format
Two space-separated integers: the indices of the matching pair (smaller index first).
Examples
4 12 3 7 5 9
1 2
Position 1 has P&L 7 and position 2 has P&L 5. 7 + 5 = 12, which equals the hedge target.
3 6 1 5 3
0 1
Position 0 has P&L 1 and position 1 has P&L 5. 1 + 5 = 6.
Constraints
- •2 ≤ n ≤ 10^5
- •-10^9 ≤ pnl[i] ≤ 10^9
- •Exactly one valid pair exists