We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bab0dda commit cce9dabCopy full SHA for cce9dab
Data-Structure/Hashing/countPairs.js
@@ -0,0 +1,21 @@
1
+'use strict';
2
+function countPairsDivideOneElement(array) {
3
+ let hm = new Map();
4
+ let maxValue = -Infinity;
5
+ let countPairs = 0;
6
+ for (let index = 0; index < array.length; index++) {
7
+ if (maxValue < array[index]) maxValue = array[index];
8
+ hm.set(array[index]);
9
+ }
10
11
+ let multiply = 2;
12
+ let k = array[index] * multiply;
13
+ while (k <= maxValue) {
14
+ if (hm.has(k)) countPairs++;
15
+ k = array[index] * (++multiply);
16
17
18
+ return countPairs;
19
+}
20
+let array = [1, 2, 3];
21
+console.log('Number of pairs that one element of pair divides other = ', countPairsDivideOneElement(array));
0 commit comments