Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69898c7

Browse files
resolve merge conflicts
2 parents b710c28 + 17eebb1 commit 69898c7

File tree

3 files changed

+125
-5
lines changed

3 files changed

+125
-5
lines changed

‎README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
1414
### Data Structures
1515

1616
- [Singly Linked List](src/_DataStructures_/LinkedList)
17+
1718
- [N Element From Last](src/_DataStructures_/LinkedList/element-from-last)
1819
- [Middle Node](src/_DataStructures_/LinkedList/middle-node)
1920
- [Detect Loop](src/_DataStructures_/LinkedList/loop-in-list)
2021
- [Reverse Linked List](src/_DataStructures_/LinkedList/reverse-linked-list)
22+
2123
- [Stack](src/_DataStructures_/Stack)
24+
2225
- [Implement Queue Using Stack](src/_DataStructures_/Stack/immitate-queue-using-stack)
2326
- [Baseball Game](src/_DataStructures_/Stack/baseball-game)
2427
- [Minimum Stack](src/_DataStructures_/Stack/min-stack)
2528
- [Balanced Parenthesis](src/_DataStructures_/Stack/balanced-parenthesis)
2629
- [Postfix Expression Evaluation](src/_DataStructures_/Stack/postfix-expression-evaluation)
27-
- [Remove Consecutive Repeated Digits](src/_DataStructures_/Stack/remove-consecutive-repeated-digits)
28-
30+
- [Remove Consecutive Repeated Digits](src/_DataStructures_/Stack/remove-consecutive-repeated-digits)
31+
-[Implement 2 Stacks using Single Array](src/_DataStructures_/Stack/2-stacks-using1-array)
2932

3033
- [Queue](src/_DataStructures_/Queue)
3134
- [Weave](src/_DataStructures_/Queue/weave)
@@ -43,6 +46,7 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
4346
- [Get Maze Path](src/_Problems_/get_subsequence)
4447
- [Get longest consecutive 1s](src/_Problems_/max-consecutive-1s)
4548
- [Get Max Char](src/_Problems_/maxchar)
49+
- [Get Smallest Common Number](src/_Problems_/get-smallest-common-number)
4650
- [Merge 2 Sorted Arrays](src/_Problems_/merge-two-sorted-arrays)
4751
- [Palindrome](src/_Problems_/palindrome)
4852
- [Product of Elements](src/_Problems_/product-of-elements)
@@ -68,9 +72,10 @@ Collection of interview questions with Unit Tests. Problems includes Data Struct
6872

6973
## CONTRIBUTION Guide
7074

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

7377
- When adding a new **problem** with solution
78+
7479
- Take care of the filename convention (Very Important)
7580
- Problem statement should be there with examples
7681
- Make sure you add the Run Time complexity of your solution
@@ -79,7 +84,8 @@ It's great to know that you want to contribute to this repo. Thanks for taking i
7984
- Strictly follow ESLINT rules
8085

8186
- When adding a Unit Test
87+
8288
- Take care of the file name convention
8389
- Make sure CI (Travis) is passing
84-
85-
Keep an eye on this guide, it's subjected to change frequently.
90+
91+
Keep an eye on this guide, it's subjected to change frequently.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Revision to PR #35 where I implemented bullshit thinking of
3+
* new breakthrough :D
4+
*/
5+
6+
class TwoStacks {
7+
constructor(capacity) {
8+
this.data = [];
9+
this.top1 = -1;
10+
this.top2 = capacity;
11+
this.overflow = new Error('Overflow: Stack is full');
12+
13+
this.capacity = capacity;
14+
}
15+
16+
push1(value) {
17+
if (this.top1 < this.top2 - 1) {
18+
this.top1 += 1;
19+
this.data[this.top1] = value;
20+
} else {
21+
throw this.overflow;
22+
}
23+
}
24+
25+
push2(value) {
26+
if (this.top1 < this.top2 - 1) {
27+
this.top2 -= 1;
28+
this.data[this.top2] = value;
29+
} else {
30+
throw this.overflow;
31+
}
32+
}
33+
34+
pop1() {
35+
if (this.top1 >= 0) {
36+
const item = this.data[this.top1];
37+
delete this.data[this.top1];
38+
this.top1 -= 1;
39+
return item;
40+
}
41+
return -1;
42+
}
43+
44+
pop2() {
45+
if (this.top2 < this.capacity) {
46+
const item = this.data[this.top2];
47+
delete this.data[this.top2];
48+
this.top2 += 1;
49+
return item;
50+
}
51+
return -1;
52+
}
53+
}
54+
55+
module.exports = TwoStacks;
56+
57+
/** Test cases */
58+
59+
/*
60+
const s = new TwoStacks(4);
61+
62+
s.push1('a');
63+
console.log(s.data);
64+
65+
s.push2('a2');
66+
console.log(s.data);
67+
68+
s.push1('b');
69+
console.log(s.data);
70+
71+
s.push2('b2');
72+
console.log(s.data);
73+
74+
s.push2('d2');
75+
console.log(s.data);
76+
77+
s.push2('c23');
78+
console.log(s.data);
79+
80+
console.log(s.pop2());
81+
console.log(s.data);
82+
83+
console.log(s.pop1());
84+
console.log(s.data);
85+
*/
Lines changed: 29 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /