Count Pairs With Target Sum
Practice Count Pairs With Target Sum for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Given an integer array nums and an integer target, return how many index pairs (i, j) with i < j satisfy nums[i] + nums[j] == target. Pairs with equal values at different positions count separately.
Example
nums = [3,3,3], target = 6 -> 3
(0,1), (0,2) and (1,2) each form a pair.
Constraints
- 0 <= nums.length <= 10^4
- -10^4 <= nums[i], target <= 10^4
Similar to LC 1 (Two Sum), which returns one pair instead of counting all of them.