You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/"view question") - [Cpp Solution](./solutions/Best%20Time%20to%20Buy%20and%20Sell%20Stock.cpp)
21
+
-[Count pairs with given sum](https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/1#"view question") - [Cpp Solution](./solutions/Count%20pairs%20with%20given%20sum.cpp)
Given an array of N integers, and an integer K, find the number of pairs of elements in the array whose sum is equal to K.
6
+
7
+
Example 1:
8
+
Input:
9
+
N = 4, K = 6
10
+
arr[] = {1, 5, 7, 1}
11
+
Output: 2
12
+
Explanation:
13
+
arr[0] + arr[1] = 1 + 5 = 6
14
+
and arr[1] + arr[3] = 5 + 1 = 6.
15
+
16
+
Example 2:
17
+
Input:
18
+
N = 4, X = 2
19
+
arr[] = {1, 1, 1, 1}
20
+
Output: 6
21
+
Explanation:
22
+
Each 1 will produce sum 2 with any 1.
23
+
Your Task:
24
+
You don't need to read input or print anything. Your task is to complete the function getPairsCount() which takes arr[], n and k as input parameters and returns the number of pairs that have sum K.
0 commit comments