Skip to content

Instantly share code, notes, and snippets.

@ArunHub
Created December 27, 2019 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArunHub/95c46b3157fcf0930535699521e8ccd7 to your computer and use it in GitHub Desktop.
Save ArunHub/95c46b3157fcf0930535699521e8ccd7 to your computer and use it in GitHub Desktop.
function distinct(arr, t) {
let count = 0;
let n = arr.length;
if(arr[n-1]<arr[n-2]){
let s = arr[n-1];
arr[n-1] = arr[n-2];
arr[n-2] = s;
}
for(var i=0;i<n-1;i++){
for(var j=i+1;j<=n;j++){
if(arr[i]<arr[j] && arr[i]+arr[j]===t){
count++
}
}
}
return count++;
}
console.log(distinct([5,3,47,3,2,9],47))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment