We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6e6c321 commit 0868c0fCopy full SHA for 0868c0f
src/_Problems_/get-smallest-common-number/index.js
@@ -0,0 +1,29 @@
1
+// Get the common smallest number between two integer arrays
2
+
3
+const getSmallestCommonNumber = (a1, a2) => {
4
+ let map = {};
5
+ let i = 0;
6
+ let min;
7
8
+ while (a1.length > i || a2.length > i) {
9
+ if (i < a1.length) {
10
+ map[`${a1[i]}a`] = true;
11
+ if (map[`${a1[i]}b`] && (min > a1[i] || !min)) {
12
+ min = a1[i];
13
+ }
14
15
16
+ if (i < a2.length) {
17
+ map[`${a2[i]}b`] = true;
18
+ if (map[`${a2[i]}a`] && (min > a2[i] || !min)) {
19
+ min = a2[i];
20
21
22
23
+ i++;
24
25
26
+ return min || -1;
27
+};
28
29
+module.exports = { getSmallestCommonNumber };
0 commit comments