Skip to content

Commit a9cc626

Browse files
authored
Merge pull request knaxus#37 from jdhrnndz/master
Implementation of finding the smallest common number
2 parents 6e6c321 + f221f9f commit a9cc626

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
1919
- [Detect Loop](src/_DataStructures_/LinkedList/loop-in-list)
2020
- [Reverse Linked List](src/_DataStructures_/LinkedList/reverse-linked-list)
2121
- [Stack](src/_DataStructures_/Stack)
22+
2223
- [Implement Queue Using Stack](src/_DataStructures_/Stack/immitate-queue-using-stack)
2324
- [Baseball Game](src/_DataStructures_/Stack/baseball-game)
2425
- [Minimum Stack](src/_DataStructures_/Stack/min-stack)
@@ -40,6 +41,7 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
4041
- [Get Maze Path](src/_Problems_/get_subsequence)
4142
- [Get longest consecutive 1s](src/_Problems_/max-consecutive-1s)
4243
- [Get Max Char](src/_Problems_/maxchar)
44+
- [Get Smallest Common Number](src/_Problems_/get-smallest-common-number)
4345
- [Merge 2 Sorted Arrays](src/_Problems_/merge-two-sorted-arrays)
4446
- [Palindrome](src/_Problems_/palindrome)
4547
- [Product of Elements](src/_Problems_/product-of-elements)
@@ -65,9 +67,10 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
6567

6668
## CONTRIBUTION Guide
6769

68-
It's great to know that you want to contribute to this repo. Thanks for taking interest. Before you start, read the following carefully.
70+
It's great to know that you want to contribute to this repo. Thanks for taking interest. Before you start, read the following carefully.
6971

7072
- When adding a new **problem** with solution
73+
7174
- Take care of the filename convention (Very Important)
7275
- Problem statement should be there with examples
7376
- Make sure you add the Run Time complexity of your solution
@@ -76,7 +79,8 @@ It's great to know that you want to contribute to this repo. Thanks for taking i
7679
- Strictly follow ESLINT rules
7780

7881
- When adding a Unit Test
82+
7983
- Take care of the file name convention
8084
- Make sure CI (Travis) is passing
81-
82-
Keep an eye on this guide, it's subjected to change frequently.
85+
86+
Keep an eye on this guide, it's subjected to change frequently.
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)