-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from VamsiKrishna04/main
Added Algorithm checkGoodPairsInArray.js
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Given an array A and a integer B. A pair(i,j) in the array is a good pair if i!=j and (A[i]+A[j]==B). Check if any good pair exist or not. | ||
|
||
function checkGoodPairsInArray(A, B){ | ||
let arrASize = A.length; | ||
// For every number traverse all numbers right to it | ||
for(let i = 0; i <(arrASize - 1); i++){ | ||
for(let j = (i + 1); j <(arrASize); j++){ | ||
if((A[i] + A[j]) == B){ | ||
return 1; | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
let A = [1,2,3,4]; | ||
let B = 7; | ||
let out = checkGoodPairsInArray(A,B); | ||
console.log(out); |