MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / isPaired

Function isPaired

CodeChef_problems/CSUM/solution.cpp:5–17  ·  view source on GitHub ↗

isPaired will define whenever the array has paired that equal to k

Source from the content-addressed store, hash-verified

3
4// isPaired will define whenever the array has paired that equal to k
5bool isPaired(vector<long long int> A, int length, int k) {
6 int left=0, right = length - 1; // init left and right pointer for upper lower bound
7
8 while(left < right) {
9 if (A[left] + A[right] < k) left++; // increase lower bound if result < k
10 else if (A[left] + A[right] > k) right--; // deacrease upper bound if result > k
11 else { // pair number is found. A[left] + A[right] = k
12 return true;
13 }
14 }
15
16 return false;
17}
18
19int main() {
20 int t, n;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected