Count pairs with given sum

Given an array arr[] and an integer targetYou have to find numbers of pairs in array arr[] which sums up to given target.


Problem link: https://www.geeksforgeeks.org/problems/count-pairs-with-given-sum--150253/1


Examples:

Input: arr[] = [1, 5, 7, -1, 5], target = 6 
Output: 3
Explanation: Pairs with sum 6 are (1, 5), (7, -1) and (1, 5). 

Examples:

Input: arr[] = [1, 1, 1, 1], target = 2 
Output: 6
Explanation: Pairs with sum 2 are (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1).
Input: arr[] = [10, 12, 10, 15, -1], target = 125
Output: 0

Constraints:
1 <= arr.size() <= 105
-104 <= arr[i] <= 104
1 <= target <= 104

Comments

Popular Posts