Skip to content

Commit 6dc3568

Browse files
committed
14/12/2020 v2
1 parent 9e23725 commit 6dc3568

File tree

2 files changed

+23
-41
lines changed

2 files changed

+23
-41
lines changed

Daily-challenge/Dec/13/README.md

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
1-
# Populating Next Right Pointers in Each Node
2-
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:
1+
# Burst Balloons
2+
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.
33

4-
struct Node {
5-
int val;
6-
Node *left;
7-
Node *right;
8-
Node *next;
9-
}
10-
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
4+
Find the maximum coins you can collect by bursting the balloons wisely.
115

12-
Initially, all next pointers are set to NULL.
6+
Note:
137

14-
8+
You may imagine nums[-1] = nums[n] = 1. They are not real therefore you can not burst them.
9+
0 ≤ n ≤ 500, 0 ≤ nums[i] ≤ 100
10+
Example:
1511

16-
Follow up:
17-
18-
You may only use constant extra space.
19-
Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
20-
21-
22-
Example 1:
23-
24-
25-
26-
Input: root = [1,2,3,4,5,6,7]
27-
Output: [1,#,2,3,#,4,5,6,7,#]
28-
Explanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.
29-
30-
31-
Constraints:
32-
33-
The number of nodes in the given tree is less than 4096.
34-
-1000 <= node.val <= 1000<br>
12+
Input: [3,1,5,8]
13+
Output: 167
14+
Explanation: nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
15+
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167<br>
3516

3617
## Idea
3718

Daily-challenge/Dec/14/README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
# Poor Pigs
1+
# Palindrome Partitioning
2+
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
23

3-
Solution
4-
There are 1000 buckets, one and only one of them is poisonous, while the rest are filled with water. They all look identical. If a pig drinks the poison it will die within 15 minutes. What is the minimum amount of pigs you need to figure out which bucket is poisonous within one hour?
5-
6-
Answer this question, and write an algorithm for the general case.
4+
A palindrome string is a string that reads the same backward as forward.
75

86

97

10-
General case:
8+
Example 1:
119

12-
If there are n buckets and a pig drinking poison will die within m minutes, how many pigs (x) you need to figure out the poisonous bucket within p minutes? There is exactly one bucket with poison.
10+
Input: s = "aab"
11+
Output: [["a","a","b"],["aa","b"]]
12+
Example 2:
1313

14+
Input: s = "a"
15+
Output: [["a"]]
1416

1517

16-
Note:
18+
Constraints:
1719

18-
A pig can be allowed to drink simultaneously on as many buckets as one would like, and the feeding takes no time.
19-
After a pig has instantly finished drinking buckets, there has to be a cool down time of m minutes. During this time, only observation is allowed and no feedings at all.
20-
Any given bucket can be sampled an infinite number of times (by an unlimited number of pigs).<br>
20+
1 <= s.length <= 16
21+
s contains only lowercase English letters.<br>
2122

2223
## Idea
2324

0 commit comments

Comments
 (0)