bowang0911/leetcode huggingface dataset:
Design Circular Queue

Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle, and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer ".

One of the benefits of the circular queue is that we can make use of the spaces in front of the queue. In a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. But using the circular queue, we can use the space to store new values.

Implement the `MyCircularQueue` class:

*   `MyCircularQueue(k)` Initializes the object with the size of the queue to be `k`.
*   `int Front()` Gets the front item from the queue. If the queue is empty, return `-1`.
*   `int Rear()` Gets the last item from the queue. If the queue is empty, return `-1`.
*   `boolean enQueue(int value)` Inserts an element into the circular queue. Return `true` if the operation is successful.
*   `boolean deQueue()` Deletes an element from the circular queue. Return `true` if the operation is successful.
*   `boolean isEmpty()` Checks whether the circular queue is empty or not.
*   `boolean isFull()` Checks whether the circular queue is full or not.

You must solve the problem without using the built-in queue data structure in your programming language.

**Example 1:**

**Input**
\[ "MyCircularQueue ",  "enQueue ",  "enQueue ",  "enQueue ",  "enQueue ",  "Rear ",  "isFull ",  "deQueue ",  "enQueue ",  "Rear "\]
\[\[3\], \[1\], \[2\], \[3\], \[4\], \[\], \[\], \[\], \[4\], \[\]\]
**Output**
\[null, true, true, true, false, 3, true, true, true, 4\]

**Explanation**
MyCircularQueue myCircularQueue = new MyCircularQueue(3);
myCircularQueue.enQueue(1); // return True
myCircularQueue.enQueue(2); // return True
myCircularQueue.enQueue(3); // return True
myCircularQueue.enQueue(4); // return False
myCircularQueue.Rear();     // return 3
myCircularQueue.isFull();   // return True
myCircularQueue.deQueue();  // return True
myCircularQueue.enQueue(4); // return True
myCircularQueue.Rear();     // return 4

**Constraints:**

*   `1 <= k <= 1000`
*   `0 <= value <= 1000`
*   At most `3000` calls will be made to `enQueue`, `deQueue`, `Front`, `Rear`, `isEmpty`, and `isFull`.
Add One Row to Tree

Given the `root` of a binary tree and two integers `val` and `depth`, add a row of nodes with value `val` at the given depth `depth`.

Note that the `root` node is at depth `1`.

The adding rule is:

*   Given the integer `depth`, for each not null tree node `cur` at the depth `depth - 1`, create two tree nodes with value `val` as `cur`'s left subtree root and right subtree root.
*   `cur`'s original left subtree should be the left subtree of the new left subtree root.
*   `cur`'s original right subtree should be the right subtree of the new right subtree root.
*   If `depth == 1` that means there is no depth `depth - 1` at all, then create a tree node with value `val` as the new root of the whole original tree, and the original tree is the new root's left subtree.

**Example 1:**

**Input:** root = \[4,2,6,3,1,5\], val = 1, depth = 2
**Output:** \[4,1,1,2,null,null,6,3,1,5\]

**Example 2:**

**Input:** root = \[4,2,null,3,1\], val = 1, depth = 3
**Output:** \[4,2,null,1,1,3,null,null,1\]

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   The depth of the tree is in the range `[1, 104]`.
*   `-100 <= Node.val <= 100`
*   `-105 <= val <= 105`
*   `1 <= depth <= the depth of tree + 1`
Maximum Distance in Arrays

You are given `m` `arrays`, where each array is sorted in **ascending order**.

You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers `a` and `b` to be their absolute difference `|a - b|`.

Return _the maximum distance_.

**Example 1:**

**Input:** arrays = \[\[1,2,3\],\[4,5\],\[1,2,3\]\]
**Output:** 4
**Explanation:** One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.

**Example 2:**

**Input:** arrays = \[\[1\],\[1\]\]
**Output:** 0

**Constraints:**

*   `m == arrays.length`
*   `2 <= m <= 105`
*   `1 <= arrays[i].length <= 500`
*   `-104 <= arrays[i][j] <= 104`
*   `arrays[i]` is sorted in **ascending order**.
*   There will be at most `105` integers in all the arrays.
Minimum Factorization

Given a positive integer num, return _the smallest positive integer_ `x` _whose multiplication of each digit equals_ `num`. If there is no answer or the answer is not fit in **32-bit** signed integer, return `0`.

**Example 1:**

**Input:** num = 48
**Output:** 68

**Example 2:**

**Input:** num = 15
**Output:** 35

**Constraints:**

*   `1 <= num <= 231 - 1`
Maximum Product of Three Numbers

Given an integer array `nums`, _find three numbers whose product is maximum and return the maximum product_.

**Example 1:**

**Input:** nums = \[1,2,3\]
**Output:** 6

**Example 2:**

**Input:** nums = \[1,2,3,4\]
**Output:** 24

**Example 3:**

**Input:** nums = \[-1,-2,-3\]
**Output:** -6

**Constraints:**

*   `3 <= nums.length <= 104`
*   `-1000 <= nums[i] <= 1000`
K Inverse Pairs Array

For an integer array `nums`, an **inverse pair** is a pair of integers `[i, j]` where `0 <= i < j < nums.length` and `nums[i] > nums[j]`.

Given two integers n and k, return the number of different arrays consist of numbers from `1` to `n` such that there are exactly `k` **inverse pairs**. Since the answer can be huge, return it **modulo** `109 + 7`.

**Example 1:**

**Input:** n = 3, k = 0
**Output:** 1
**Explanation:** Only the array \[1,2,3\] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.

**Example 2:**

**Input:** n = 3, k = 1
**Output:** 2
**Explanation:** The array \[1,3,2\] and \[2,1,3\] have exactly 1 inverse pair.

**Constraints:**

*   `1 <= n <= 1000`
*   `0 <= k <= 1000`
Course Schedule III

There are `n` different online courses numbered from `1` to `n`. You are given an array `courses` where `courses[i] = [durationi, lastDayi]` indicate that the `ith` course should be taken **continuously** for `durationi` days and must be finished before or on `lastDayi`.

You will start on the `1st` day and you cannot take two or more courses simultaneously.

Return _the maximum number of courses that you can take_.

**Example 1:**

**Input:** courses = \[\[100,200\],\[200,1300\],\[1000,1250\],\[2000,3200\]\]
**Output:** 3
Explanation: 
There are totally 4 courses, but you can take 3 courses at most:
First, take the 1st course, it costs 100 days so you will finish it on the 100th day, and ready to take the next course on the 101st day.
Second, take the 3rd course, it costs 1000 days so you will finish it on the 1100th day, and ready to take the next course on the 1101st day. 
Third, take the 2nd course, it costs 200 days so you will finish it on the 1300th day. 
The 4th course cannot be taken now, since you will finish it on the 3300th day, which exceeds the closed date.

**Example 2:**

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

**Example 3:**

**Input:** courses = \[\[3,2\],\[4,3\]\]
**Output:** 0

**Constraints:**

*   `1 <= courses.length <= 104`
*   `1 <= durationi, lastDayi <= 104`
Design Excel Sum Formula

Design the basic function of **Excel** and implement the function of the sum formula.

Implement the `Excel` class:

*   `Excel(int height, char width)` Initializes the object with the `height` and the `width` of the sheet. The sheet is an integer matrix `mat` of size `height x width` with the row index in the range `[1, height]` and the column index in the range `['A', width]`. All the values should be **zero** initially.
*   `void set(int row, char column, int val)` Changes the value at `mat[row][column]` to be `val`.
*   `int get(int row, char column)` Returns the value at `mat[row][column]`.
*   `int sum(int row, char column, List numbers)` Sets the value at `mat[row][column]` to be the sum of cells represented by `numbers` and returns the value at `mat[row][column]`. This sum formula **should exist** until this cell is overlapped by another value or another sum formula. `numbers[i]` could be on the format:
    *   `"ColRow "` that represents a single cell.
        *   For example, `"F7 "` represents the cell `mat[7]['F']`.
    *   `"ColRow1:ColRow2 "` that represents a range of cells. The range will always be a rectangle where `"ColRow1 "` represent the position of the top-left cell, and `"ColRow2 "` represents the position of the bottom-right cell.
        *   For example, `"B3:F7 "` represents the cells `mat[i][j]` for `3 <= i <= 7` and `'B' <= j <= 'F'`.

**Note:** You could assume that there will not be any circular sum reference.

*   For example, `mat[1]['A'] == sum(1, "B ")` and `mat[1]['B'] == sum(1, "A ")`.

**Example 1:**

**Input**
\[ "Excel ",  "set ",  "sum ",  "set ",  "get "\]
\[\[3,  "C "\], \[1,  "A ", 2\], \[3,  "C ", \[ "A1 ",  "A1:B2 "\]\], \[2,  "B ", 2\], \[3,  "C "\]\]
**Output**
\[null, null, 4, null, 6\]

**Explanation**
Excel excel = new Excel(3,  "C ");
 // construct a 3\*3 2D array with all zero.
 //   A B C
 // 1 0 0 0
 // 2 0 0 0
 // 3 0 0 0
excel.set(1,  "A ", 2);
 // set mat\[1\]\[ "A "\] to be 2.
 //   A B C
 // 1 2 0 0
 // 2 0 0 0
 // 3 0 0 0
excel.sum(3,  "C ", \[ "A1 ",  "A1:B2 "\]); // return 4
 // set mat\[3\]\[ "C "\] to be the sum of value at mat\[1\]\[ "A "\] and the values sum of the rectangle range whose top-left cell is mat\[1\]\[ "A "\] and bottom-right cell is mat\[2\]\[ "B "\].
 //   A B C
 // 1 2 0 0
 // 2 0 0 0
 // 3 0 0 4
excel.set(2,  "B ", 2);
 // set mat\[2\]\[ "B "\] to be 2. Note mat\[3\]\[ "C "\] should also be changed.
 //   A B C
 // 1 2 0 0
 // 2 0 2 0
 // 3 0 0 6
excel.get(3,  "C "); // return 6

**Constraints:**

*   `1 <= height <= 26`
*   `'A' <= width <= 'Z'`
*   `1 <= row <= height`
*   `'A' <= column <= width`
*   `-100 <= val <= 100`
*   `1 <= numbers.length <= 5`
*   `numbers[i]` has the format `"ColRow "` or `"ColRow1:ColRow2 "`.
*   At most `100` calls will be made to `set`, `get`, and `sum`.
Smallest Range Covering Elements from K Lists

You have `k` lists of sorted integers in **non-decreasing order**. Find the **smallest** range that includes at least one number from each of the `k` lists.

We define the range `[a, b]` is smaller than range `[c, d]` if `b - a < d - c` **or** `a < c` if `b - a == d - c`.

**Example 1:**

**Input:** nums = \[\[4,10,15,24,26\],\[0,9,12,20\],\[5,18,22,30\]\]
**Output:** \[20,24\]
**Explanation:** 
List 1: \[4, 10, 15, 24,26\], 24 is in range \[20,24\].
List 2: \[0, 9, 12, 20\], 20 is in range \[20,24\].
List 3: \[5, 18, 22, 30\], 22 is in range \[20,24\].

**Example 2:**

**Input:** nums = \[\[1,2,3\],\[1,2,3\],\[1,2,3\]\]
**Output:** \[1,1\]

**Constraints:**

*   `nums.length == k`
*   `1 <= k <= 3500`
*   `1 <= nums[i].length <= 50`
*   `-105 <= nums[i][j] <= 105`
*   `nums[i]` is sorted in **non-decreasing** order.
Sum of Square Numbers

Given a non-negative integer `c`, decide whether there're two integers `a` and `b` such that `a2 + b2 = c`.

**Example 1:**

**Input:** c = 5
**Output:** true
**Explanation:** 1 \* 1 + 2 \* 2 = 5

**Example 2:**

**Input:** c = 3
**Output:** false

**Constraints:**

*   `0 <= c <= 231 - 1`
Find the Derangement of An Array

In combinatorial mathematics, a **derangement** is a permutation of the elements of a set, such that no element appears in its original position.

You are given an integer `n`. There is originally an array consisting of `n` integers from `1` to `n` in ascending order, return _the number of **derangements** it can generate_. Since the answer may be huge, return it **modulo** `109 + 7`.

**Example 1:**

**Input:** n = 3
**Output:** 2
**Explanation:** The original array is \[1,2,3\]. The two derangements are \[2,3,1\] and \[3,1,2\].

**Example 2:**

**Input:** n = 2
**Output:** 1

**Constraints:**

*   `1 <= n <= 106`
Design Log Storage System

You are given several logs, where each log contains a unique ID and timestamp. Timestamp is a string that has the following format: `Year:Month:Day:Hour:Minute:Second`, for example, `2017:01:01:23:59:59`. All domains are zero-padded decimal numbers.

Implement the `LogSystem` class:

*   `LogSystem()` Initializes the `LogSystem` object.
*   `void put(int id, string timestamp)` Stores the given log `(id, timestamp)` in your storage system.
*   `int[] retrieve(string start, string end, string granularity)` Returns the IDs of the logs whose timestamps are within the range from `start` to `end` inclusive. `start` and `end` all have the same format as `timestamp`, and `granularity` means how precise the range should be (i.e. to the exact `Day`, `Minute`, etc.). For example, `start = "2017:01:01:23:59:59 "`, `end = "2017:01:02:23:59:59 "`, and `granularity = "Day "` means that we need to find the logs within the inclusive range from **Jan. 1st 2017** to **Jan. 2nd 2017**, and the `Hour`, `Minute`, and `Second` for each log entry can be ignored.

**Example 1:**

**Input**
\[ "LogSystem ",  "put ",  "put ",  "put ",  "retrieve ",  "retrieve "\]
\[\[\], \[1,  "2017:01:01:23:59:59 "\], \[2,  "2017:01:01:22:59:59 "\], \[3,  "2016:01:01:00:00:00 "\], \[ "2016:01:01:01:01:01 ",  "2017:01:01:23:00:00 ",  "Year "\], \[ "2016:01:01:01:01:01 ",  "2017:01:01:23:00:00 ",  "Hour "\]\]
**Output**
\[null, null, null, null, \[3, 2, 1\], \[2, 1\]\]

**Explanation**
LogSystem logSystem = new LogSystem();
logSystem.put(1,  "2017:01:01:23:59:59 ");
logSystem.put(2,  "2017:01:01:22:59:59 ");
logSystem.put(3,  "2016:01:01:00:00:00 ");

// return \[3,2,1\], because you need to return all logs between 2016 and 2017.
logSystem.retrieve( "2016:01:01:01:01:01 ",  "2017:01:01:23:00:00 ",  "Year ");

// return \[2,1\], because you need to return all logs between Jan. 1, 2016 01:XX:XX and Jan. 1, 2017 23:XX:XX.
// Log 3 is not returned because Jan. 1, 2016 00:00:00 comes before the start of the range.
logSystem.retrieve( "2016:01:01:01:01:01 ",  "2017:01:01:23:00:00 ",  "Hour ");

**Constraints:**

*   `1 <= id <= 500`
*   `2000 <= Year <= 2017`
*   `1 <= Month <= 12`
*   `1 <= Day <= 31`
*   `0 <= Hour <= 23`
*   `0 <= Minute, Second <= 59`
*   `granularity` is one of the values `[ "Year ", "Month ", "Day ", "Hour ", "Minute ", "Second "]`.
*   At most `500` calls will be made to `put` and `retrieve`.
Average of Levels in Binary Tree

Given the `root` of a binary tree, return _the average value of the nodes on each level in the form of an array_. Answers within `10-5` of the actual answer will be accepted.

**Example 1:**

**Input:** root = \[3,9,20,null,null,15,7\]
**Output:** \[3.00000,14.50000,11.00000\]
Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.
Hence return \[3, 14.5, 11\].

**Example 2:**

**Input:** root = \[3,9,20,15,7\]
**Output:** \[3.00000,14.50000,11.00000\]

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   `-231 <= Node.val <= 231 - 1`
Shopping Offers

In LeetCode Store, there are `n` items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.

You are given an integer array `price` where `price[i]` is the price of the `ith` item, and an integer array `needs` where `needs[i]` is the number of pieces of the `ith` item you want to buy.

You are also given an array `special` where `special[i]` is of size `n + 1` where `special[i][j]` is the number of pieces of the `jth` item in the `ith` offer and `special[i][n]` (i.e., the last integer in the array) is the price of the `ith` offer.

Return _the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers_. You are not allowed to buy more items than you want, even if that would lower the overall price. You could use any of the special offers as many times as you want.

**Example 1:**

**Input:** price = \[2,5\], special = \[\[3,0,5\],\[1,2,10\]\], needs = \[3,2\]
**Output:** 14
**Explanation:** There are two kinds of items, A and B. Their prices are $2 and $5 respectively. 
In special offer 1, you can pay $5 for 3A and 0B
In special offer 2, you can pay $10 for 1A and 2B. 
You need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.

**Example 2:**

**Input:** price = \[2,3,4\], special = \[\[1,1,0,4\],\[2,2,1,9\]\], needs = \[1,2,1\]
**Output:** 11
**Explanation:** The price of A is $2, and $3 for B, $4 for C. 
You may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C. 
You need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C. 
You cannot add more items, though only $9 for 2A ,2B and 1C.

**Constraints:**

*   `n == price.length == needs.length`
*   `1 <= n <= 6`
*   `0 <= price[i], needs[i] <= 10`
*   `1 <= special.length <= 100`
*   `special[i].length == n + 1`
*   `0 <= special[i][j] <= 50`
Decode Ways II

A message containing letters from `A-Z` can be **encoded** into numbers using the following mapping:

'A' ->  "1 "
'B' ->  "2 "
...
'Z' ->  "26 "

To **decode** an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, `"11106 "` can be mapped into:

*   `"AAJF "` with the grouping `(1 1 10 6)`
*   `"KJF "` with the grouping `(11 10 6)`

Note that the grouping `(1 11 06)` is invalid because `"06 "` cannot be mapped into `'F'` since `"6 "` is different from `"06 "`.

**In addition** to the mapping above, an encoded message may contain the `'*'` character, which can represent any digit from `'1'` to `'9'` (`'0'` is excluded). For example, the encoded message `"1* "` may represent any of the encoded messages `"11 "`, `"12 "`, `"13 "`, `"14 "`, `"15 "`, `"16 "`, `"17 "`, `"18 "`, or `"19 "`. Decoding `"1* "` is equivalent to decoding **any** of the encoded messages it can represent.

Given a string `s` consisting of digits and `'*'` characters, return _the **number** of ways to **decode** it_.

Since the answer may be very large, return it **modulo** `109 + 7`.

**Example 1:**

**Input:** s =  "\* "
**Output:** 9
**Explanation:** The encoded message can represent any of the encoded messages  "1 ",  "2 ",  "3 ",  "4 ",  "5 ",  "6 ",  "7 ",  "8 ", or  "9 ".
Each of these can be decoded to the strings  "A ",  "B ",  "C ",  "D ",  "E ",  "F ",  "G ",  "H ", and  "I " respectively.
Hence, there are a total of 9 ways to decode  "\* ".

**Example 2:**

**Input:** s =  "1\* "
**Output:** 18
**Explanation:** The encoded message can represent any of the encoded messages  "11 ",  "12 ",  "13 ",  "14 ",  "15 ",  "16 ",  "17 ",  "18 ", or  "19 ".
Each of these encoded messages have 2 ways to be decoded (e.g.  "11 " can be decoded to  "AA " or  "K ").
Hence, there are a total of 9 \* 2 = 18 ways to decode  "1\* ".

**Example 3:**

**Input:** s =  "2\* "
**Output:** 15
**Explanation:** The encoded message can represent any of the encoded messages  "21 ",  "22 ",  "23 ",  "24 ",  "25 ",  "26 ",  "27 ",  "28 ", or  "29 ".
 "21 ",  "22 ",  "23 ",  "24 ",  "25 ", and  "26 " have 2 ways of being decoded, but  "27 ",  "28 ", and  "29 " only have 1 way.
Hence, there are a total of (6 \* 2) + (3 \* 1) = 12 + 3 = 15 ways to decode  "2\* ".

**Constraints:**

*   `1 <= s.length <= 105`
*   `s[i]` is a digit or `'*'`.
Solve the Equation

Solve a given equation and return the value of `'x'` in the form of a string `"x=#value "`. The equation contains only `'+'`, `'-'` operation, the variable `'x'` and its coefficient. You should return `"No solution "` if there is no solution for the equation, or `"Infinite solutions "` if there are infinite solutions for the equation.

If there is exactly one solution for the equation, we ensure that the value of `'x'` is an integer.

**Example 1:**

**Input:** equation =  "x+5-3+x=6+x-2 "
**Output:**  "x=2 "

**Example 2:**

**Input:** equation =  "x=x "
**Output:**  "Infinite solutions "

**Example 3:**

**Input:** equation =  "2x=x "
**Output:**  "x=0 "

**Constraints:**

*   `3 <= equation.length <= 1000`
*   `equation` has exactly one `'='`.
*   `equation` consists of integers with an absolute value in the range `[0, 100]` without any leading zeros, and the variable `'x'`.
Design Circular Deque

Design your implementation of the circular double-ended queue (deque).

Implement the `MyCircularDeque` class:

*   `MyCircularDeque(int k)` Initializes the deque with a maximum size of `k`.
*   `boolean insertFront()` Adds an item at the front of Deque. Returns `true` if the operation is successful, or `false` otherwise.
*   `boolean insertLast()` Adds an item at the rear of Deque. Returns `true` if the operation is successful, or `false` otherwise.
*   `boolean deleteFront()` Deletes an item from the front of Deque. Returns `true` if the operation is successful, or `false` otherwise.
*   `boolean deleteLast()` Deletes an item from the rear of Deque. Returns `true` if the operation is successful, or `false` otherwise.
*   `int getFront()` Returns the front item from the Deque. Returns `-1` if the deque is empty.
*   `int getRear()` Returns the last item from Deque. Returns `-1` if the deque is empty.
*   `boolean isEmpty()` Returns `true` if the deque is empty, or `false` otherwise.
*   `boolean isFull()` Returns `true` if the deque is full, or `false` otherwise.

**Example 1:**

**Input**
\[ "MyCircularDeque ",  "insertLast ",  "insertLast ",  "insertFront ",  "insertFront ",  "getRear ",  "isFull ",  "deleteLast ",  "insertFront ",  "getFront "\]
\[\[3\], \[1\], \[2\], \[3\], \[4\], \[\], \[\], \[\], \[4\], \[\]\]
**Output**
\[null, true, true, true, false, 2, true, true, true, 4\]

**Explanation**
MyCircularDeque myCircularDeque = new MyCircularDeque(3);
myCircularDeque.insertLast(1);  // return True
myCircularDeque.insertLast(2);  // return True
myCircularDeque.insertFront(3); // return True
myCircularDeque.insertFront(4); // return False, the queue is full.
myCircularDeque.getRear();      // return 2
myCircularDeque.isFull();       // return True
myCircularDeque.deleteLast();   // return True
myCircularDeque.insertFront(4); // return True
myCircularDeque.getFront();     // return 4

**Constraints:**

*   `1 <= k <= 1000`
*   `0 <= value <= 1000`
*   At most `2000` calls will be made to `insertFront`, `insertLast`, `deleteFront`, `deleteLast`, `getFront`, `getRear`, `isEmpty`, `isFull`.
Maximum Average Subarray I

You are given an integer array `nums` consisting of `n` elements, and an integer `k`.

Find a contiguous subarray whose **length is equal to** `k` that has the maximum average value and return _this value_. Any answer with a calculation error less than `10-5` will be accepted.

**Example 1:**

**Input:** nums = \[1,12,-5,-6,50,3\], k = 4
**Output:** 12.75000
**Explanation:** Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75

**Example 2:**

**Input:** nums = \[5\], k = 1
**Output:** 5.00000

**Constraints:**

*   `n == nums.length`
*   `1 <= k <= n <= 105`
*   `-104 <= nums[i] <= 104`
Maximum Average Subarray II

You are given an integer array `nums` consisting of `n` elements, and an integer `k`.

Find a contiguous subarray whose **length is greater than or equal to** `k` that has the maximum average value and return _this value_. Any answer with a calculation error less than `10-5` will be accepted.

**Example 1:**

**Input:** nums = \[1,12,-5,-6,50,3\], k = 4
**Output:** 12.75000
**Explanation:**
\- When the length is 4, averages are \[0.5, 12.75, 10.5\] and the maximum average is 12.75
- When the length is 5, averages are \[10.4, 10.8\] and the maximum average is 10.8
- When the length is 6, averages are \[9.16667\] and the maximum average is 9.16667
The maximum average is when we choose a subarray of length 4 (i.e., the sub array \[12, -5, -6, 50\]) which has the max average 12.75, so we return 12.75
Note that we do not consider the subarrays of length < 4.

**Example 2:**

**Input:** nums = \[5\], k = 1
**Output:** 5.00000

**Constraints:**

*   `n == nums.length`
*   `1 <= k <= n <= 104`
*   `-104 <= nums[i] <= 104`