Skip to content
QuantReadySign In
#039easyArrays

Matching Hedge Pairs

Time Limit: 2sMemory: 256MB

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) and target (the hedge target sum).
  • Second line: n space-separated integers representing P&L values.

Output Format

Two space-separated integers: the indices of the matching pair (smaller index first).

Examples

Example 1
Input
4 12
3 7 5 9
Output
1 2

Position 1 has P&L 7 and position 2 has P&L 5. 7 + 5 = 12, which equals the hedge target.

Example 2
Input
3 6
1 5 3
Output
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
Loading interactive editor…