|
1 |
| -# Find the Smallest Divisor Given a Threshold |
2 |
| -Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. |
| 1 | +# Populating Next Right Pointers in Each Node II |
| 2 | +Given a binary tree |
3 | 3 |
|
4 |
| -Each result of division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5). |
| 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. |
5 | 11 |
|
6 |
| -It is guaranteed that there will be an answer. |
| 12 | +Initially, all next pointers are set to NULL. |
7 | 13 |
|
8 | 14 |
|
9 | 15 |
|
| 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 | + |
10 | 22 | Example 1:
|
11 | 23 |
|
12 |
| -Input: nums = [1,2,5,9], threshold = 6 |
13 |
| -Output: 5 |
14 |
| -Explanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1. |
15 |
| -If the divisor is 4 we can get a sum to 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2). |
16 |
| -Example 2: |
17 | 24 |
|
18 |
| -Input: nums = [2,3,5,7,11], threshold = 11 |
19 |
| -Output: 3 |
20 |
| -Example 3: |
21 | 25 |
|
22 |
| -Input: nums = [19], threshold = 5 |
23 |
| -Output: 4 |
| 26 | +Input: root = [1,2,3,4,5,null,7] |
| 27 | +Output: [1,#,2,3,#,4,5,7,#] |
| 28 | +Explanation: Given the above 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. |
24 | 29 |
|
25 | 30 |
|
26 | 31 | Constraints:
|
27 | 32 |
|
28 |
| -1 <= nums.length <= 5 * 10^4 |
29 |
| -1 <= nums[i] <= 10^6 |
30 |
| -nums.length <= threshold <= 10^6 <br> |
| 33 | +The number of nodes in the given tree is less than 6000. |
| 34 | +-100 <= node.val <= 100 <br> |
31 | 35 |
|
32 | 36 | ## Idea
|
33 | 37 | yea ill ttyl
|
|
0 commit comments