Skip to content

Commit ab2223a

Browse files
committed
-
1 parent ebfa937 commit ab2223a

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,23 @@ Given the mapping `a = 1, b = 2, ... z = 26`, and an encoded message, count the
100100
For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.
101101
You can assume that the messages are decodable. For example, '001' is not allowed.
102102

103+
[JS](pb7/answer.js) (Not timed, very long)
104+
105+
### 8
106+
> This problem was asked by Google.
107+
108+
A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value.
109+
Given the root to a binary tree, count the number of unival subtrees.
110+
For example, the following tree has 5 unival subtrees:
111+
112+
```
113+
0
114+
/ \
115+
1 0
116+
/ \
117+
1 0
118+
/ \
119+
1 1
120+
```
121+
122+
[JS](pb7/answer.js) (Not timed)

pb9/Problem.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
> This problem was asked by Airbnb.
2+
3+
Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative.
4+
For example, `[2, 4, 6, 2, 5]` should return `13`, since we pick 2, 6, and 5. `[5, 1, 1, 5]` should return `10`, since we pick 5 and 5.
5+
Follow-up: Can you do this in O(N) time and constant space?

pb9/answer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const i1 = [2, 4, 6, 2, 5];
2+
const i2 = [5, 1, 1, 5];
3+
4+
const nonAdjSum = (input) => {
5+
const orig = [...input];
6+
const nbMax = input.length % 2 ===0 ? Math.trunc(input.length / 2) : Math.trunc(input.length / 2) +1;
7+
input.sort((a,b) => {
8+
if(a>b)
9+
return -1
10+
return 1
11+
})
12+
13+
console.log(nbMax)
14+
console.log(orig)
15+
console.log(input)
16+
}
17+
18+
console.log(nonAdjSum(i1));

0 commit comments

Comments
 (0)