Skip to content

Commit 9adc35e

Browse files
Update concepts
1 parent dc870c5 commit 9adc35e

File tree

4 files changed

+112
-66
lines changed

4 files changed

+112
-66
lines changed

concepts/HttpRequests-solutions.js renamed to concepts/HttpRequests-solutions.md

Lines changed: 27 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
/////////////////
2-
// //
3-
// CHALLENGE 1 //
4-
// //
5-
/////////////////
61

7-
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
8-
// console.log('Start of Challenge 1');
9-
// ...your code below
2+
### CHALLENGE 1
103

4+
```js
115
console.log("I am at the beginning of the code");
126

137
setTimeout(function() { console.log("I am in the setTimeout callback function after 3 seconds(3000ms)");}, 3000)
148

159
console.log("I am at the end of the code");
1610

1711

18-
1912
// console.log('End of Challenge 1');
2013
// */// (do not alter this line)
14+
```
2115

16+
### CHALLENGE 2
2217

23-
24-
25-
/////////////////
26-
// //
27-
// CHALLENGE 2 //
28-
// //
29-
/////////////////
30-
18+
```js
3119
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
3220
console.log('Start of Challenge 2');
3321
// ...your code below
@@ -49,15 +37,12 @@ function clearAllIntervals() {
4937
}
5038
console.log('End of Challenge 2');
5139
// */// (do not alter this line)
40+
```
5241

5342

43+
### CHALLENGE 3
5444

55-
/////////////////
56-
// //
57-
// CHALLENGE 3 //
58-
// //
59-
/////////////////
60-
45+
```js
6146
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
6247
console.log('Start of Challenge 3');
6348
// ...your code below
@@ -82,16 +67,12 @@ function everyXSecsForYsecs(callback, xSecs, ySecs) {
8267

8368
console.log('End of Challenge 3');
8469
// */// (do not alter this line)
70+
```
8571

8672

73+
### CHALLENGE 4
8774

88-
89-
/////////////////
90-
// //
91-
// CHALLENGE 4 //
92-
// //
93-
/////////////////
94-
75+
```js
9576
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
9677
console.log('Start of Challenge 4');
9778
// ...your code below
@@ -113,15 +94,12 @@ forEach(delays, delayLog);
11394

11495
console.log('End of Challenge 4');
11596
// */// (do not alter this line)
97+
```
11698

11799

100+
### CHALLENGE 5
118101

119-
/////////////////
120-
// //
121-
// CHALLENGE 5 //
122-
// //
123-
/////////////////
124-
102+
```js
125103
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
126104
console.log('Start of Challenge 5');
127105
// ...your code below
@@ -149,15 +127,12 @@ activateButton.addEventListener("click", function() {
149127
document.body.style.background = '#def';
150128
console.log('End of Challenge 3');
151129
// */// (do not alter this line)
130+
```
152131

153132

133+
### CHALLENGE 6
154134

155-
/////////////////
156-
// //
157-
// CHALLENGE 6 //
158-
// //
159-
/////////////////
160-
135+
```js
161136
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
162137
console.log('Start of Challenge 6');
163138
var dataReceived;
@@ -186,15 +161,12 @@ console.log("Data is ", dataReceived);
186161

187162
console.log('End of Challenge 6');
188163
// */// (do not alter this line)
164+
```
189165

190166

167+
### CHALLENGE 7
191168

192-
/////////////////
193-
// //
194-
// CHALLENGE 7 //
195-
// //
196-
/////////////////
197-
169+
```js
198170
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
199171
console.log('Start of Challenge 7');
200172
// ...your code below
@@ -218,15 +190,12 @@ request.send();
218190

219191
console.log('End of Challenge 7');
220192
// */// (do not alter this line)
193+
```
221194

222195

196+
### CHALLENGE 8
223197

224-
/////////////////
225-
// //
226-
// CHALLENGE 8 //
227-
// //
228-
/////////////////
229-
198+
```js
230199
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
231200
console.log('Start of Challenge 8');
232201
// ...your code below
@@ -257,15 +226,12 @@ requestEvents.send();
257226

258227
console.log('End of Challenge 8');
259228
// */// (do not alter this line)
229+
```
260230

261231

232+
### CHALLENGE 9
262233

263-
/////////////////
264-
// //
265-
// CHALLENGE 9 //
266-
// //
267-
/////////////////
268-
234+
```js
269235
// /* <<<=== Remove the first two slashes (//) to comment out this challenge when finished
270236
console.log('Start of Challenge 9');
271237
// ...your code below
@@ -293,11 +259,7 @@ requestEventsInUsa.open("GET", eventsAPIUSA);
293259
requestEventsInUsa.send();
294260

295261

296-
297-
298-
299-
300262
console.log('End of Challenge 9');
301263
// */// (do not alter this line)
302-
264+
```
303265

exercises/leetcode/amazon/numberOfIslands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const numberOfIslands = grid => {
3232

3333
const isLand = (x, y) => {
3434
return x > -1 && x < grid.length && y > -1 &&
35-
y < grid[0].length && grid[x, y] !== '0';
35+
y < grid[0].length && grid[x][y] !== '0';
3636
}
3737

3838
const removeIsland = (startX, startY) => {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class TreeNode {
2+
constructor(val) {
3+
this.val = val;
4+
this.left = null;
5+
this.right = null;
6+
}
7+
}
8+
let ans;
9+
10+
const maxDepth = node => {
11+
if (!node) {
12+
return 0;
13+
}
14+
15+
let left = depth(node.left);
16+
let right = depth(node.right);
17+
18+
ans = Math.max(ans, left + right + 1);
19+
20+
return Math.max(left, right) + 1;
21+
}
22+
const diameterOfBinaryTree = root => {
23+
ans = 1;
24+
maxDepth(root);
25+
return ans - 1;
26+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Given a non-empty binary tree, find the maximum path sum.
3+
4+
For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.
5+
6+
Example 1:
7+
8+
Input: [1,2,3]
9+
10+
1
11+
/ \
12+
2 3
13+
14+
Output: 6
15+
Example 2:
16+
17+
Input: [-10,9,20,null,null,15,7]
18+
19+
-10
20+
/ \
21+
9 20
22+
/ \
23+
15 7
24+
25+
Output: 42
26+
*/
27+
28+
class TreeNode {
29+
constructor(val) {
30+
this.val = val;
31+
this.left = null;
32+
this.right = null;
33+
}
34+
}
35+
36+
let maxSum;
37+
38+
const maxGain = node => {
39+
if (!node) {
40+
return Number.NEGATIVE_INFINITY;
41+
}
42+
43+
let leftGain = Math.max(maxGain(node.left), 0);
44+
let rightGain = Math.max(maxGain(node.right), 0);
45+
46+
let newPathMax = node.val + leftGain + rightGain;
47+
48+
maxSum = Math.max(maxSum, newPathMax);
49+
50+
return node.val + Math.max(leftGain, rightGain);
51+
}
52+
const maxPathSum = root => {
53+
maxSum = Number.NEGATIVE_INFINITY;
54+
55+
maxGain(root);
56+
57+
return maxSum;
58+
}

0 commit comments

Comments
 (0)