bowang0911/leetcode huggingface dataset:
Statistics from a Large Sample

You are given a large sample of integers in the range `[0, 255]`. Since the sample is so large, it is represented by an array `count` where `count[k]` is the **number of times** that `k` appears in the sample.

Calculate the following statistics:

*   `minimum`: The minimum element in the sample.
*   `maximum`: The maximum element in the sample.
*   `mean`: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.
*   `median`:
    *   If the sample has an odd number of elements, then the `median` is the middle element once the sample is sorted.
    *   If the sample has an even number of elements, then the `median` is the average of the two middle elements once the sample is sorted.
*   `mode`: The number that appears the most in the sample. It is guaranteed to be **unique**.

Return _the statistics of the sample as an array of floating-point numbers_ `[minimum, maximum, mean, median, mode]`_. Answers within_ `10-5` _of the actual answer will be accepted._

**Example 1:**

**Input:** count = \[0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\]
**Output:** \[1.00000,3.00000,2.37500,2.50000,3.00000\]
**Explanation:** The sample represented by count is \[1,2,2,2,3,3,3,3\].
The minimum and maximum are 1 and 3 respectively.
The mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.
Since the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.
The mode is 3 as it appears the most in the sample.

**Example 2:**

**Input:** count = \[0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\]
**Output:** \[1.00000,4.00000,2.18182,2.00000,1.00000\]
**Explanation:** The sample represented by count is \[1,1,1,1,2,2,2,3,3,4,4\].
The minimum and maximum are 1 and 4 respectively.
The mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).
Since the size of the sample is odd, the median is the middle element 2.
The mode is 1 as it appears the most in the sample.

**Constraints:**

*   `count.length == 256`
*   `0 <= count[i] <= 109`
*   `1 <= sum(count) <= 109`
*   The mode of the sample that `count` represents is **unique**.
Car Pooling

There is a car with `capacity` empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).

You are given the integer `capacity` and an array `trips` where `trips[i] = [numPassengersi, fromi, toi]` indicates that the `ith` trip has `numPassengersi` passengers and the locations to pick them up and drop them off are `fromi` and `toi` respectively. The locations are given as the number of kilometers due east from the car's initial location.

Return `true` _if it is possible to pick up and drop off all passengers for all the given trips, or_ `false` _otherwise_.

**Example 1:**

**Input:** trips = \[\[2,1,5\],\[3,3,7\]\], capacity = 4
**Output:** false

**Example 2:**

**Input:** trips = \[\[2,1,5\],\[3,3,7\]\], capacity = 5
**Output:** true

**Constraints:**

*   `1 <= trips.length <= 1000`
*   `trips[i].length == 3`
*   `1 <= numPassengersi <= 100`
*   `0 <= fromi < toi <= 1000`
*   `1 <= capacity <= 105`
Find in Mountain Array

_(This problem is an **interactive problem**.)_

You may recall that an array `arr` is a **mountain array** if and only if:

*   `arr.length >= 3`
*   There exists some `i` with `0 < i < arr.length - 1` such that:
    *   `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]`
    *   `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]`

Given a mountain array `mountainArr`, return the **minimum** `index` such that `mountainArr.get(index) == target`. If such an `index` does not exist, return `-1`.

**You cannot access the mountain array directly.** You may only access the array using a `MountainArray` interface:

*   `MountainArray.get(k)` returns the element of the array at index `k` (0-indexed).
*   `MountainArray.length()` returns the length of the array.

Submissions making more than `100` calls to `MountainArray.get` will be judged _Wrong Answer_. Also, any solutions that attempt to circumvent the judge will result in disqualification.

**Example 1:**

**Input:** array = \[1,2,3,4,5,3,1\], target = 3
**Output:** 2
**Explanation:** 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.

**Example 2:**

**Input:** array = \[0,1,2,4,2,1\], target = 3
**Output:** -1
**Explanation:** 3 does not exist in `the array,` so we return -1.

**Constraints:**

*   `3 <= mountain_arr.length() <= 104`
*   `0 <= target <= 109`
*   `0 <= mountain_arr.get(index) <= 109`
Brace Expansion II

Under the grammar given below, strings can represent a set of lowercase words. Let `R(expr)` denote the set of words the expression represents.

The grammar can best be understood through simple examples:

*   Single letters represent a singleton set containing that word.
    *   `R( "a ") = { "a "}`
    *   `R( "w ") = { "w "}`
*   When we take a comma-delimited list of two or more expressions, we take the union of possibilities.
    *   `R( "{a,b,c} ") = { "a ", "b ", "c "}`
    *   `R( "{{a,b},{b,c}} ") = { "a ", "b ", "c "}` (notice the final set only contains each word at most once)
*   When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.
    *   `R( "{a,b}{c,d} ") = { "ac ", "ad ", "bc ", "bd "}`
    *   `R( "a{b,c}{d,e}f{g,h} ") = { "abdfg ", "abdfh ", "abefg ", "abefh ", "acdfg ", "acdfh ", "acefg ", "acefh "}`

Formally, the three rules for our grammar:

*   For every lowercase letter `x`, we have `R(x) = {x}`.
*   For expressions `e1, e2, ... , ek` with `k >= 2`, we have `R({e1, e2, ...}) = R(e1) ∪ R(e2) ∪ ...`
*   For expressions `e1` and `e2`, we have `R(e1 + e2) = {a + b for (a, b) in R(e1) * R(e2)}`, where `+` denotes concatenation, and `*` denotes the cartesian product.

Given an expression representing a set of words under the given grammar, return _the sorted list of words that the expression represents_.

**Example 1:**

**Input:** expression =  "{a,b}{c,{d,e}} "
**Output:** \[ "ac ", "ad ", "ae ", "bc ", "bd ", "be "\]

**Example 2:**

**Input:** expression =  "{{a,z},a{b,c},{ab,z}} "
**Output:** \[ "a ", "ab ", "ac ", "z "\]
**Explanation:** Each distinct word is written only once in the final answer.

**Constraints:**

*   `1 <= expression.length <= 60`
*   `expression[i]` consists of `'{'`, `'}'`, `','`or lowercase English letters.
*   The given `expression` represents a set of words based on the grammar given in the description.
Two Sum Less Than K

Given an array `nums` of integers and integer `k`, return the maximum `sum` such that there exists `i < j` with `nums[i] + nums[j] = sum` and `sum < k`. If no `i`, `j` exist satisfying this equation, return `-1`.

**Example 1:**

**Input:** nums = \[34,23,1,24,75,33,54,8\], k = 60
**Output:** 58
**Explanation:** We can use 34 and 24 to sum 58 which is less than 60.

**Example 2:**

**Input:** nums = \[10,20,30\], k = 15
**Output:** -1
**Explanation:** In this case it is not possible to get a pair sum less that 15.

**Constraints:**

*   `1 <= nums.length <= 100`
*   `1 <= nums[i] <= 1000`
*   `1 <= k <= 2000`
Find K-Length Substrings With No Repeated Characters

Given a string `s` and an integer `k`, return _the number of substrings in_ `s` _of length_ `k` _with no repeated characters_.

**Example 1:**

**Input:** s =  "havefunonleetcode ", k = 5
**Output:** 6
**Explanation:** There are 6 substrings they are: 'havef','avefu','vefun','efuno','etcod','tcode'.

**Example 2:**

**Input:** s =  "home ", k = 5
**Output:** 0
**Explanation:** Notice k can be larger than the length of s. In this case, it is not possible to find any substring.

**Constraints:**

*   `1 <= s.length <= 104`
*   `s` consists of lowercase English letters.
*   `1 <= k <= 104`
The Earliest Moment When Everyone Become Friends

There are n people in a social group labeled from `0` to `n - 1`. You are given an array `logs` where `logs[i] = [timestampi, xi, yi]` indicates that `xi` and `yi` will be friends at the time `timestampi`.

Friendship is **symmetric**. That means if `a` is friends with `b`, then `b` is friends with `a`. Also, person `a` is acquainted with a person `b` if `a` is friends with `b`, or `a` is a friend of someone acquainted with `b`.

Return _the earliest time for which every person became acquainted with every other person_. If there is no such earliest time, return `-1`.

**Example 1:**

**Input:** logs = \[\[20190101,0,1\],\[20190104,3,4\],\[20190107,2,3\],\[20190211,1,5\],\[20190224,2,4\],\[20190301,0,3\],\[20190312,1,2\],\[20190322,4,5\]\], n = 6
**Output:** 20190301
**Explanation:** 
The first event occurs at timestamp = 20190101, and after 0 and 1 become friends, we have the following friendship groups \[0,1\], \[2\], \[3\], \[4\], \[5\].
The second event occurs at timestamp = 20190104, and after 3 and 4 become friends, we have the following friendship groups \[0,1\], \[2\], \[3,4\], \[5\].
The third event occurs at timestamp = 20190107, and after 2 and 3 become friends, we have the following friendship groups \[0,1\], \[2,3,4\], \[5\].
The fourth event occurs at timestamp = 20190211, and after 1 and 5 become friends, we have the following friendship groups \[0,1,5\], \[2,3,4\].
The fifth event occurs at timestamp = 20190224, and as 2 and 4 are already friends, nothing happens.
The sixth event occurs at timestamp = 20190301, and after 0 and 3 become friends, we all become friends.

**Example 2:**

**Input:** logs = \[\[0,2,0\],\[1,0,1\],\[3,0,3\],\[4,1,2\],\[7,3,1\]\], n = 4
**Output:** 3
**Explanation:** At timestamp = 3, all the persons (i.e., 0, 1, 2, and 3) become friends.

**Constraints:**

*   `2 <= n <= 100`
*   `1 <= logs.length <= 104`
*   `logs[i].length == 3`
*   `0 <= timestampi <= 109`
*   `0 <= xi, yi <= n - 1`
*   `xi != yi`
*   All the values `timestampi` are **unique**.
*   All the pairs `(xi, yi)` occur at most one time in the input.
Path With Maximum Minimum Value

Given an `m x n` integer matrix `grid`, return _the maximum **score** of a path starting at_ `(0, 0)` _and ending at_ `(m - 1, n - 1)` moving in the 4 cardinal directions.

The **score** of a path is the minimum value in that path.

*   For example, the score of the path `8 -> 4 -> 5 -> 9` is `4`.

**Example 1:**

**Input:** grid = \[\[5,4,5\],\[1,2,6\],\[7,4,6\]\]
**Output:** 4
**Explanation:** The path with the maximum score is highlighted in yellow. 

**Example 2:**

**Input:** grid = \[\[2,2,1,2,2,2\],\[1,2,2,2,1,2\]\]
**Output:** 2

**Example 3:**

**Input:** grid = \[\[3,4,6,3,4\],\[0,2,1,1,7\],\[8,8,3,2,7\],\[3,2,4,9,8\],\[4,1,2,0,0\],\[4,6,5,4,3\]\]
**Output:** 3

**Constraints:**

*   `m == grid.length`
*   `n == grid[i].length`
*   `1 <= m, n <= 100`
*   `0 <= grid[i][j] <= 109`
Distribute Candies to People

We distribute some number of `candies`, to a row of **`n = num_people`** people in the following way:

We then give 1 candy to the first person, 2 candies to the second person, and so on until we give `n` candies to the last person.

Then, we go back to the start of the row, giving `n + 1` candies to the first person, `n + 2` candies to the second person, and so on until we give `2 * n` candies to the last person.

This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies. The last person will receive all of our remaining candies (not necessarily one more than the previous gift).

Return an array (of length `num_people` and sum `candies`) that represents the final distribution of candies.

**Example 1:**

**Input:** candies = 7, num\_people = 4
**Output:** \[1,2,3,1\]
**Explanation:**
On the first turn, ans\[0\] += 1, and the array is \[1,0,0,0\].
On the second turn, ans\[1\] += 2, and the array is \[1,2,0,0\].
On the third turn, ans\[2\] += 3, and the array is \[1,2,3,0\].
On the fourth turn, ans\[3\] += 1 (because there is only one candy left), and the final array is \[1,2,3,1\].

**Example 2:**

**Input:** candies = 10, num\_people = 3
**Output:** \[5,2,3\]
**Explanation:** 
On the first turn, ans\[0\] += 1, and the array is \[1,0,0\].
On the second turn, ans\[1\] += 2, and the array is \[1,2,0\].
On the third turn, ans\[2\] += 3, and the array is \[1,2,3\].
On the fourth turn, ans\[0\] += 4, and the final array is \[5,2,3\].

**Constraints:**

*   1 <= candies <= 10^9
*   1 <= num\_people <= 1000
Path In Zigzag Labelled Binary Tree

In an infinite binary tree where every node has two children, the nodes are labelled in row order.

In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.

Given the `label` of a node in this tree, return the labels in the path from the root of the tree to the node with that `label`.

**Example 1:**

**Input:** label = 14
**Output:** \[1,3,4,14\]

**Example 2:**

**Input:** label = 26
**Output:** \[1,2,6,10,26\]

**Constraints:**

*   `1 <= label <= 10^6`
Filling Bookcase Shelves

You are given an array `books` where `books[i] = [thicknessi, heighti]` indicates the thickness and height of the `ith` book. You are also given an integer `shelfWidth`.

We want to place these books in order onto bookcase shelves that have a total width `shelfWidth`.

We choose some of the books to place on this shelf such that the sum of their thickness is less than or equal to `shelfWidth`, then build another level of the shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.

Note that at each step of the above process, the order of the books we place is the same order as the given sequence of books.

*   For example, if we have an ordered list of `5` books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.

Return _the minimum possible height that the total bookshelf can be after placing shelves in this manner_.

**Example 1:**

**Input:** books = \[\[1,1\],\[2,3\],\[2,3\],\[1,1\],\[1,1\],\[1,1\],\[1,2\]\], shelfWidth = 4
**Output:** 6
**Explanation:**
The sum of the heights of the 3 shelves is 1 + 3 + 2 = 6.
Notice that book number 2 does not have to be on the first shelf.

**Example 2:**

**Input:** books = \[\[1,3\],\[2,4\],\[3,2\]\], shelfWidth = 6
**Output:** 4

**Constraints:**

*   `1 <= books.length <= 1000`
*   `1 <= thicknessi <= shelfWidth <= 1000`
*   `1 <= heighti <= 1000`
Parsing A Boolean Expression

A **boolean expression** is an expression that evaluates to either `true` or `false`. It can be in one of the following shapes:

*   `'t'` that evaluates to `true`.
*   `'f'` that evaluates to `false`.
*   `'!(subExpr)'` that evaluates to **the logical NOT** of the inner expression `subExpr`.
*   `'&(subExpr1, subExpr2, ..., subExprn)'` that evaluates to **the logical AND** of the inner expressions `subExpr1, subExpr2, ..., subExprn` where `n >= 1`.
*   `'|(subExpr1, subExpr2, ..., subExprn)'` that evaluates to **the logical OR** of the inner expressions `subExpr1, subExpr2, ..., subExprn` where `n >= 1`.

Given a string `expression` that represents a **boolean expression**, return _the evaluation of that expression_.

It is **guaranteed** that the given expression is valid and follows the given rules.

**Example 1:**

**Input:** expression =  "&(|(f)) "
**Output:** false
**Explanation:** 
First, evaluate |(f) --> f. The expression is now  "&(f) ".
Then, evaluate &(f) --> f. The expression is now  "f ".
Finally, return false.

**Example 2:**

**Input:** expression =  "|(f,f,f,t) "
**Output:** true
**Explanation:** The evaluation of (false OR false OR false OR true) is true.

**Example 3:**

**Input:** expression =  "!(&(f,t)) "
**Output:** true
**Explanation:** 
First, evaluate &(f,t) --> (false AND true) --> false --> f. The expression is now  "!(f) ".
Then, evaluate !(f) --> NOT false --> true. We return true.

**Constraints:**

*   `1 <= expression.length <= 2 * 104`
*   expression\[i\] is one following characters: `'('`, `')'`, `'&'`, `'|'`, `'!'`, `'t'`, `'f'`, and `','`.
Defanging an IP Address

Given a valid (IPv4) IP `address`, return a defanged version of that IP address.

A _defanged IP address_ replaces every period `". "` with `"[.] "`.

**Example 1:**

**Input:** address = "1.1.1.1"
**Output:** "1\[.\]1\[.\]1\[.\]1"

**Example 2:**

**Input:** address = "255.100.50.0"
**Output:** "255\[.\]100\[.\]50\[.\]0"

**Constraints:**

*   The given `address` is a valid IPv4 address.
Corporate Flight Bookings

There are `n` flights that are labeled from `1` to `n`.

You are given an array of flight bookings `bookings`, where `bookings[i] = [firsti, lasti, seatsi]` represents a booking for flights `firsti` through `lasti` (**inclusive**) with `seatsi` seats reserved for **each flight** in the range.

Return _an array_ `answer` _of length_ `n`_, where_ `answer[i]` _is the total number of seats reserved for flight_ `i`.

**Example 1:**

**Input:** bookings = \[\[1,2,10\],\[2,3,20\],\[2,5,25\]\], n = 5
**Output:** \[10,55,45,25,25\]
**Explanation:**
Flight labels:        1   2   3   4   5
Booking 1 reserved:  10  10
Booking 2 reserved:      20  20
Booking 3 reserved:      25  25  25  25
Total seats:         10  55  45  25  25
Hence, answer = \[10,55,45,25,25\]

**Example 2:**

**Input:** bookings = \[\[1,2,10\],\[2,2,15\]\], n = 2
**Output:** \[10,25\]
**Explanation:**
Flight labels:        1   2
Booking 1 reserved:  10  10
Booking 2 reserved:      15
Total seats:         10  25
Hence, answer = \[10,25\]

**Constraints:**

*   `1 <= n <= 2 * 104`
*   `1 <= bookings.length <= 2 * 104`
*   `bookings[i].length == 3`
*   `1 <= firsti <= lasti <= n`
*   `1 <= seatsi <= 104`
Delete Nodes And Return Forest

Given the `root` of a binary tree, each node in the tree has a distinct value.

After deleting all nodes with a value in `to_delete`, we are left with a forest (a disjoint union of trees).

Return the roots of the trees in the remaining forest. You may return the result in any order.

**Example 1:**

**Input:** root = \[1,2,3,4,5,6,7\], to\_delete = \[3,5\]
**Output:** \[\[1,2,null,4\],\[6\],\[7\]\]

**Example 2:**

**Input:** root = \[1,2,4,null,3\], to\_delete = \[3\]
**Output:** \[\[1,2,4\]\]

**Constraints:**

*   The number of nodes in the given tree is at most `1000`.
*   Each node has a distinct value between `1` and `1000`.
*   `to_delete.length <= 1000`
*   `to_delete` contains distinct values between `1` and `1000`.
Maximum Nesting Depth of Two Valid Parentheses Strings

A string is a _valid parentheses string_ (denoted VPS) if and only if it consists of `"( "` and `") "` characters only, and:

*   It is the empty string, or
*   It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are VPS's, or
*   It can be written as `(A)`, where `A` is a VPS.

We can similarly define the _nesting depth_ `depth(S)` of any VPS `S` as follows:

*   `depth( " ") = 0`
*   `depth(A + B) = max(depth(A), depth(B))`, where `A` and `B` are VPS's
*   `depth( "( " + A + ") ") = 1 + depth(A)`, where `A` is a VPS.

For example, `" "`, `"()() "`, and `"()(()()) "` are VPS's (with nesting depths 0, 1, and 2), and `")( "` and `"(() "` are not VPS's.

Given a VPS seq, split it into two disjoint subsequences `A` and `B`, such that `A` and `B` are VPS's (and `A.length + B.length = seq.length`).

Now choose **any** such `A` and `B` such that `max(depth(A), depth(B))` is the minimum possible value.

Return an `answer` array (of length `seq.length`) that encodes such a choice of `A` and `B`: `answer[i] = 0` if `seq[i]` is part of `A`, else `answer[i] = 1`. Note that even though multiple answers may exist, you may return any of them.

**Example 1:**

**Input:** seq =  "(()()) "
**Output:** \[0,1,1,1,1,0\]

**Example 2:**

**Input:** seq =  "()(())() "
**Output:** \[0,0,0,1,1,0,1,1\]

**Constraints:**

*   `1 <= seq.size <= 10000`
Number of Days in a Month

Given a year `year` and a month `month`, return _the number of days of that month_.

**Example 1:**

**Input:** year = 1992, month = 7
**Output:** 31

**Example 2:**

**Input:** year = 2000, month = 2
**Output:** 29

**Example 3:**

**Input:** year = 1900, month = 2
**Output:** 28

**Constraints:**

*   `1583 <= year <= 2100`
*   `1 <= month <= 12`
Remove Vowels from a String

Given a string `s`, remove the vowels `'a'`, `'e'`, `'i'`, `'o'`, and `'u'` from it, and return the new string.

**Example 1:**

**Input:** s =  "leetcodeisacommunityforcoders "
**Output:**  "ltcdscmmntyfrcdrs "

**Example 2:**

**Input:** s =  "aeiou "
**Output:**  " "

**Constraints:**

*   `1 <= s.length <= 1000`
*   `s` consists of only lowercase English letters.
Maximum Average Subtree

Given the `root` of a binary tree, return _the maximum **average** value of a **subtree** of that tree_. Answers within `10-5` of the actual answer will be accepted.

A **subtree** of a tree is any node of that tree plus all its descendants.

The **average** value of a tree is the sum of its values, divided by the number of nodes.

**Example 1:**

**Input:** root = \[5,6,1\]
**Output:** 6.00000
**Explanation:** 
For the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.
For the node with value = 6 we have an average of 6 / 1 = 6.
For the node with value = 1 we have an average of 1 / 1 = 1.
So the answer is 6 which is the maximum.

**Example 2:**

**Input:** root = \[0,null,1\]
**Output:** 1.00000

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   `0 <= Node.val <= 105`
Divide Array Into Increasing Sequences

Given an integer array `nums` sorted in non-decreasing order and an integer `k`, return `true` _if this array can be divided into one or more disjoint increasing subsequences of length at least_ `k`_, or_ `false` _otherwise_.

**Example 1:**

**Input:** nums = \[1,2,2,3,3,4,4\], k = 3
**Output:** true
**Explanation:** The array can be divided into two subsequences \[1,2,3,4\] and \[2,3,4\] with lengths at least 3 each.

**Example 2:**

**Input:** nums = \[5,6,6,7,8\], k = 3
**Output:** false
**Explanation:** There is no way to divide the array using the conditions required.

**Constraints:**

*   `1 <= k <= nums.length <= 105`
*   `1 <= nums[i] <= 105`
*   `nums` is sorted in non-decreasing order.
Relative Sort Array

Given two arrays `arr1` and `arr2`, the elements of `arr2` are distinct, and all elements in `arr2` are also in `arr1`.

Sort the elements of `arr1` such that the relative ordering of items in `arr1` are the same as in `arr2`. Elements that do not appear in `arr2` should be placed at the end of `arr1` in **ascending** order.

**Example 1:**

**Input:** arr1 = \[2,3,1,3,2,4,6,7,9,2,19\], arr2 = \[2,1,4,3,9,6\]
**Output:** \[2,2,2,1,4,3,3,9,6,7,19\]

**Example 2:**

**Input:** arr1 = \[28,6,22,8,44,17\], arr2 = \[22,28,8,6\]
**Output:** \[22,28,8,6,17,44\]

**Constraints:**

*   `1 <= arr1.length, arr2.length <= 1000`
*   `0 <= arr1[i], arr2[i] <= 1000`
*   All the elements of `arr2` are **distinct**.
*   Each `arr2[i]` is in `arr1`.