Count Index Pairs with a Target Sum
Problem statement
Return the number of index pairs (i,j) with i < j and nums[i] + nums[j] == target. Equal values at different indices form distinct pairs.
Function
countTargetPairs(nums: int[], target: int) → longExamples
Example 1
nums = [1,2,1,1,2]target = 3return = 6Each of three 1s pairs with each of two 2s.
Constraints
0 <= nums.length <= 2 * 10^5.- The answer fits in signed 64-bit range.