Practice · 5 of 5
Pair Summing to K
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Given n integers (values 0..10^6) and a target k,
count how many **unordered pairs** (i < j) satisfy a[i] + a[j] = k.
**Input:** Line 1: n k (2 ≤ n ≤ 10^5, 0 ≤ k ≤ 2·10^6). Line 2: n integers.
**Output:** One integer — the number of pairs.
**Example:** 5 6 / 1 5 2 4 5 → pairs (1,5), (2,4) and (5... wait: values
1+5=6 gives two pairs (with both 5s), 2+4=6 gives one → total 3.
Press Submit to check your solution.
Back to lesson: Practice: Marking Array Set