bowang0911/leetcode huggingface dataset:
Maximum Number of Achievable Transfer Requests

We have `n` buildings numbered from `0` to `n - 1`. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.

You are given an array `requests` where `requests[i] = [fromi, toi]` represents an employee's request to transfer from building `fromi` to building `toi`.

**All buildings are full**, so a list of requests is achievable only if for each building, the **net change in employee transfers is zero**. This means the number of employees **leaving** is **equal** to the number of employees **moving in**. For example if `n = 3` and two employees are leaving building `0`, one is leaving building `1`, and one is leaving building `2`, there should be two employees moving to building `0`, one employee moving to building `1`, and one employee moving to building `2`.

Return _the maximum number of achievable requests_.

**Example 1:**

**Input:** n = 5, requests = \[\[0,1\],\[1,0\],\[0,1\],\[1,2\],\[2,0\],\[3,4\]\]
**Output:** 5
**Explantion:** Let's see the requests:
From building 0 we have employees x and y and both want to move to building 1.
From building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.
From building 2 we have employee z and they want to move to building 0.
From building 3 we have employee c and they want to move to building 4.
From building 4 we don't have any requests.
We can achieve the requests of users x and b by swapping their places.
We can achieve the requests of users y, a and z by swapping the places in the 3 buildings.

**Example 2:**

**Input:** n = 3, requests = \[\[0,0\],\[1,2\],\[2,1\]\]
**Output:** 3
**Explantion:** Let's see the requests:
From building 0 we have employee x and they want to stay in the same building 0.
From building 1 we have employee y and they want to move to building 2.
From building 2 we have employee z and they want to move to building 1.
We can achieve all the requests. 

**Example 3:**

**Input:** n = 4, requests = \[\[0,3\],\[3,1\],\[1,2\],\[2,0\]\]
**Output:** 4

**Constraints:**

*   `1 <= n <= 20`
*   `1 <= requests.length <= 16`
*   `requests[i].length == 2`
*   `0 <= fromi, toi < n`
Find Nearest Right Node in Binary Tree

Given the `root` of a binary tree and a node `u` in the tree, return _the **nearest** node on the **same level** that is to the **right** of_ `u`_, or return_ `null` _if_ `u` _is the rightmost node in its level_.

**Example 1:**

**Input:** root = \[1,2,3,null,4,5,6\], u = 4
**Output:** 5
**Explanation:** The nearest node on the same level to the right of node 4 is node 5.

**Example 2:**

**Input:** root = \[3,null,4,2\], u = 2
**Output:** null
**Explanation:** There are no nodes to the right of 2.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 105]`.
*   `1 <= Node.val <= 105`
*   All values in the tree are **distinct**.
*   `u` is a node in the binary tree rooted at `root`.
Design Parking System

Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.

Implement the `ParkingSystem` class:

*   `ParkingSystem(int big, int medium, int small)` Initializes object of the `ParkingSystem` class. The number of slots for each parking space are given as part of the constructor.
*   `bool addCar(int carType)` Checks whether there is a parking space of `carType` for the car that wants to get into the parking lot. `carType` can be of three kinds: big, medium, or small, which are represented by `1`, `2`, and `3` respectively. **A car can only park in a parking space of its** `carType`. If there is no space available, return `false`, else park the car in that size space and return `true`.

**Example 1:**

**Input**
\[ "ParkingSystem ",  "addCar ",  "addCar ",  "addCar ",  "addCar "\]
\[\[1, 1, 0\], \[1\], \[2\], \[3\], \[1\]\]
**Output**
\[null, true, true, false, false\]

**Explanation**
ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
parkingSystem.addCar(1); // return true because there is 1 available slot for a big car
parkingSystem.addCar(2); // return true because there is 1 available slot for a medium car
parkingSystem.addCar(3); // return false because there is no available slot for a small car
parkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.

**Constraints:**

*   `0 <= big, medium, small <= 1000`
*   `carType` is `1`, `2`, or `3`
*   At most `1000` calls will be made to `addCar`
Alert Using Same Key-Card Three or More Times in a One Hour Period

LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an **alert** if any worker uses the key-card **three or more times** in a one-hour period.

You are given a list of strings `keyName` and `keyTime` where `[keyName[i], keyTime[i]]` corresponds to a person's name and the time when their key-card was used **in a** **single day**.

Access times are given in the **24-hour time format "HH:MM "**, such as `"23:51 "` and `"09:49 "`.

Return a _list of unique worker names who received an alert for frequent keycard use_. Sort the names in **ascending order alphabetically**.

Notice that `"10:00 "` - `"11:00 "` is considered to be within a one-hour period, while `"22:51 "` - `"23:52 "` is not considered to be within a one-hour period.

**Example 1:**

**Input:** keyName = \[ "daniel ", "daniel ", "daniel ", "luis ", "luis ", "luis ", "luis "\], keyTime = \[ "10:00 ", "10:40 ", "11:00 ", "09:00 ", "11:00 ", "13:00 ", "15:00 "\]
**Output:** \[ "daniel "\]
**Explanation:**  "daniel " used the keycard 3 times in a one-hour period ( "10:00 ", "10:40 ",  "11:00 ").

**Example 2:**

**Input:** keyName = \[ "alice ", "alice ", "alice ", "bob ", "bob ", "bob ", "bob "\], keyTime = \[ "12:01 ", "12:00 ", "18:00 ", "21:00 ", "21:20 ", "21:30 ", "23:00 "\]
**Output:** \[ "bob "\]
**Explanation:**  "bob " used the keycard 3 times in a one-hour period ( "21:00 ", "21:20 ",  "21:30 ").

**Constraints:**

*   `1 <= keyName.length, keyTime.length <= 105`
*   `keyName.length == keyTime.length`
*   `keyTime[i]` is in the format **"HH:MM "**.
*   `[keyName[i], keyTime[i]]` is **unique**.
*   `1 <= keyName[i].length <= 10`
*   `keyName[i] contains only lowercase English letters.`
Find Valid Matrix Given Row and Column Sums

You are given two arrays `rowSum` and `colSum` of non-negative integers where `rowSum[i]` is the sum of the elements in the `ith` row and `colSum[j]` is the sum of the elements of the `jth` column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.

Find any matrix of **non-negative** integers of size `rowSum.length x colSum.length` that satisfies the `rowSum` and `colSum` requirements.

Return _a 2D array representing **any** matrix that fulfills the requirements_. It's guaranteed that **at least one** matrix that fulfills the requirements exists.

**Example 1:**

**Input:** rowSum = \[3,8\], colSum = \[4,7\]
**Output:** \[\[3,0\],
         \[1,7\]\]
**Explanation:** 
0th row: 3 + 0 = 3 == rowSum\[0\]
1st row: 1 + 7 = 8 == rowSum\[1\]
0th column: 3 + 1 = 4 == colSum\[0\]
1st column: 0 + 7 = 7 == colSum\[1\]
The row and column sums match, and all matrix elements are non-negative.
Another possible matrix is: \[\[1,2\],
                             \[3,5\]\]

**Example 2:**

**Input:** rowSum = \[5,7,10\], colSum = \[8,6,8\]
**Output:** \[\[0,5,0\],
         \[6,1,0\],
         \[2,0,8\]\]

**Constraints:**

*   `1 <= rowSum.length, colSum.length <= 500`
*   `0 <= rowSum[i], colSum[i] <= 108`
*   `sum(rowSum) == sum(colSum)`
Find Servers That Handled Most Number of Requests

You have `k` servers numbered from `0` to `k-1` that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but **cannot handle more than one request at a time**. The requests are assigned to servers according to a specific algorithm:

*   The `ith` (0-indexed) request arrives.
*   If all servers are busy, the request is dropped (not handled at all).
*   If the `(i % k)th` server is available, assign the request to that server.
*   Otherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the `ith` server is busy, try to assign the request to the `(i+1)th` server, then the `(i+2)th` server, and so on.

You are given a **strictly increasing** array `arrival` of positive integers, where `arrival[i]` represents the arrival time of the `ith` request, and another array `load`, where `load[i]` represents the load of the `ith` request (the time it takes to complete). Your goal is to find the **busiest server(s)**. A server is considered **busiest** if it handled the most number of requests successfully among all the servers.

Return _a list containing the IDs (0-indexed) of the **busiest server(s)**_. You may return the IDs in any order.

**Example 1:**

**Input:** k = 3, arrival = \[1,2,3,4,5\], load = \[5,2,3,3,3\] 
**Output:** \[1\] 
**Explanation:** 
All of the servers start out available.
The first 3 requests are handled by the first 3 servers in order.
Request 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.
Request 4 comes in. It cannot be handled since all servers are busy, so it is dropped.
Servers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.

**Example 2:**

**Input:** k = 3, arrival = \[1,2,3,4\], load = \[1,2,1,2\]
**Output:** \[0\]
**Explanation:** 
The first 3 requests are handled by first 3 servers.
Request 3 comes in. It is handled by server 0 since the server is available.
Server 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.

**Example 3:**

**Input:** k = 3, arrival = \[1,2,3\], load = \[10,12,11\]
**Output:** \[0,1,2\]
**Explanation:** Each server handles a single request, so they are all considered the busiest.

**Constraints:**

*   `1 <= k <= 105`
*   `1 <= arrival.length, load.length <= 105`
*   `arrival.length == load.length`
*   `1 <= arrival[i], load[i] <= 109`
*   `arrival` is **strictly increasing**.
Special Array With X Elements Greater Than or Equal X

You are given an array `nums` of non-negative integers. `nums` is considered **special** if there exists a number `x` such that there are **exactly** `x` numbers in `nums` that are **greater than or equal to** `x`.

Notice that `x` **does not** have to be an element in `nums`.

Return `x` _if the array is **special**, otherwise, return_ `-1`. It can be proven that if `nums` is special, the value for `x` is **unique**.

**Example 1:**

**Input:** nums = \[3,5\]
**Output:** 2
**Explanation:** There are 2 values (3 and 5) that are greater than or equal to 2.

**Example 2:**

**Input:** nums = \[0,0\]
**Output:** -1
**Explanation:** No numbers fit the criteria for x.
If x = 0, there should be 0 numbers >= x, but there are 2.
If x = 1, there should be 1 number >= x, but there are 0.
If x = 2, there should be 2 numbers >= x, but there are 0.
x cannot be greater since there are only 2 numbers in nums.

**Example 3:**

**Input:** nums = \[0,4,3,0,4\]
**Output:** 3
**Explanation:** There are 3 values that are greater than or equal to 3.

**Constraints:**

*   `1 <= nums.length <= 100`
*   `0 <= nums[i] <= 1000`
Even Odd Tree

A binary tree is named **Even-Odd** if it meets the following conditions:

*   The root of the binary tree is at level index `0`, its children are at level index `1`, their children are at level index `2`, etc.
*   For every **even-indexed** level, all nodes at the level have **odd** integer values in **strictly increasing** order (from left to right).
*   For every **odd-indexed** level, all nodes at the level have **even** integer values in **strictly decreasing** order (from left to right).

Given the `root` of a binary tree, _return_ `true` _if the binary tree is **Even-Odd**, otherwise return_ `false`_._

**Example 1:**

**Input:** root = \[1,10,4,3,null,7,9,12,8,6,null,null,2\]
**Output:** true
**Explanation:** The node values on each level are:
Level 0: \[1\]
Level 1: \[10,4\]
Level 2: \[3,7,9\]
Level 3: \[12,8,6,2\]
Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.

**Example 2:**

**Input:** root = \[5,4,2,3,3,7\]
**Output:** false
**Explanation:** The node values on each level are:
Level 0: \[5\]
Level 1: \[4,2\]
Level 2: \[3,3,7\]
Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.

**Example 3:**

**Input:** root = \[5,9,1,3,5,7\]
**Output:** false
**Explanation:** Node values in the level 1 should be even integers.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 105]`.
*   `1 <= Node.val <= 106`
Maximum Number of Visible Points

You are given an array `points`, an integer `angle`, and your `location`, where `location = [posx, posy]` and `points[i] = [xi, yi]` both denote **integral coordinates** on the X-Y plane.

Initially, you are facing directly east from your position. You **cannot move** from your position, but you can **rotate**. In other words, `posx` and `posy` cannot be changed. Your field of view in **degrees** is represented by `angle`, determining how wide you can see from any given view direction. Let `d` be the amount in degrees that you rotate counterclockwise. Then, your field of view is the **inclusive** range of angles `[d - angle/2, d + angle/2]`.

Your browser does not support the video tag or this video format.

You can **see** some set of points if, for each point, the **angle** formed by the point, your position, and the immediate east direction from your position is **in your field of view**.

There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.

Return _the maximum number of points you can see_.

**Example 1:**

**Input:** points = \[\[2,1\],\[2,2\],\[3,3\]\], angle = 90, location = \[1,1\]
**Output:** 3
**Explanation:** The shaded region represents your field of view. All points can be made visible in your field of view, including \[3,3\] even though \[2,2\] is in front and in the same line of sight.

**Example 2:**

**Input:** points = \[\[2,1\],\[2,2\],\[3,4\],\[1,1\]\], angle = 90, location = \[1,1\]
**Output:** 4
**Explanation:** All points can be made visible in your field of view, including the one at your location.

**Example 3:**

**Input:** points = \[\[1,0\],\[2,1\]\], angle = 13, location = \[1,1\]
**Output:** 1
**Explanation:** You can only see one of the two points, as shown above.

**Constraints:**

*   `1 <= points.length <= 105`
*   `points[i].length == 2`
*   `location.length == 2`
*   `0 <= angle < 360`
*   `0 <= posx, posy, xi, yi <= 100`
Minimum One Bit Operations to Make Integers Zero

Given an integer `n`, you must transform it into `0` using the following operations any number of times:

*   Change the rightmost (`0th`) bit in the binary representation of `n`.
*   Change the `ith` bit in the binary representation of `n` if the `(i-1)th` bit is set to `1` and the `(i-2)th` through `0th` bits are set to `0`.

Return _the minimum number of operations to transform_ `n` _into_ `0`_._

**Example 1:**

**Input:** n = 3
**Output:** 2
**Explanation:** The binary representation of 3 is  "11 ".
 "11 " ->  "01 " with the 2nd operation since the 0th bit is 1.
 "01 " ->  "00 " with the 1st operation.

**Example 2:**

**Input:** n = 6
**Output:** 4
**Explanation:** The binary representation of 6 is  "110 ".
 "110 " ->  "010 " with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.
 "010 " ->  "011 " with the 1st operation.
 "011 " ->  "001 " with the 2nd operation since the 0th bit is 1.
 "001 " ->  "000 " with the 1st operation.

**Constraints:**

*   `0 <= n <= 109`
Check If Two Expression Trees are Equivalent

A **[binary expression tree](https://en.wikipedia.org/wiki/Binary_expression_tree)** is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (variables), and internal nodes (nodes with two children) correspond to the operators. In this problem, we only consider the `'+'` operator (i.e. addition).

You are given the roots of two binary expression trees, `root1` and `root2`. Return `true` _if the two binary expression trees are equivalent_. Otherwise, return `false`.

Two binary expression trees are equivalent if they **evaluate to the same value** regardless of what the variables are set to.

**Example 1:**

**Input:** root1 = \[x\], root2 = \[x\]
**Output:** true

**Example 2:**

**Input:** root1 = \[+,a,+,null,null,b,c\], root2 = \[+,+,a,b,c\]
**Output:** true
**Explaination:** `a + (b + c) == (b + c) + a`

**Example 3:**

**Input:** root1 = \[+,a,+,null,null,b,c\], root2 = \[+,+,a,b,d\]
**Output:** false
**Explaination:** `a + (b + c) != (b + d) + a`

**Constraints:**

*   The number of nodes in both trees are equal, odd and, in the range `[1, 4999]`.
*   `Node.val` is `'+'` or a lower-case English letter.
*   It's **guaranteed** that the tree given is a valid binary expression tree.

**Follow up:** What will you change in your solution if the tree also supports the `'-'` operator (i.e. subtraction)?
Maximum Nesting Depth of the Parentheses

A string is a **valid parentheses string** (denoted **VPS**) if it meets one of the following:

*   It is an empty string `" "`, or a single character not equal to `"( "` 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(C) = 0`, where `C` is a string with a single character not equal to `"( "` or `") "`.
*   `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** represented as string `s`, return _the **nesting depth** of_ `s`.

**Example 1:**

**Input:** s =  "(1+(2\*3)+((8)/4))+1 "
**Output:** 3
**Explanation:** Digit 8 is inside of 3 nested parentheses in the string.

**Example 2:**

**Input:** s =  "(1)+((2))+(((3))) "
**Output:** 3

**Constraints:**

*   `1 <= s.length <= 100`
*   `s` consists of digits `0-9` and characters `'+'`, `'-'`, `'*'`, `'/'`, `'('`, and `')'`.
*   It is guaranteed that parentheses expression `s` is a **VPS**.
Maximal Network Rank

There is an infrastructure of `n` cities with some number of `roads` connecting these cities. Each `roads[i] = [ai, bi]` indicates that there is a bidirectional road between cities `ai` and `bi`.

The **network rank** of **two different cities** is defined as the total number of **directly** connected roads to **either** city. If a road is directly connected to both cities, it is only counted **once**.

The **maximal network rank** of the infrastructure is the **maximum network rank** of all pairs of different cities.

Given the integer `n` and the array `roads`, return _the **maximal network rank** of the entire infrastructure_.

**Example 1:**

**Input:** n = 4, roads = \[\[0,1\],\[0,3\],\[1,2\],\[1,3\]\]
**Output:** 4
**Explanation:** The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.

**Example 2:**

**Input:** n = 5, roads = \[\[0,1\],\[0,3\],\[1,2\],\[1,3\],\[2,3\],\[2,4\]\]
**Output:** 5
**Explanation:** There are 5 roads that are connected to cities 1 or 2.

**Example 3:**

**Input:** n = 8, roads = \[\[0,1\],\[1,2\],\[2,3\],\[2,4\],\[5,6\],\[5,7\]\]
**Output:** 5
**Explanation:** The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.

**Constraints:**

*   `2 <= n <= 100`
*   `0 <= roads.length <= n * (n - 1) / 2`
*   `roads[i].length == 2`
*   `0 <= ai, bi <= n-1`
*   `ai != bi`
*   Each pair of cities has **at most one** road connecting them.
Split Two Strings to Make Palindrome

You are given two strings `a` and `b` of the same length. Choose an index and split both strings **at the same index**, splitting `a` into two strings: `aprefix` and `asuffix` where `a = aprefix + asuffix`, and splitting `b` into two strings: `bprefix` and `bsuffix` where `b = bprefix + bsuffix`. Check if `aprefix + bsuffix` or `bprefix + asuffix` forms a palindrome.

When you split a string `s` into `sprefix` and `ssuffix`, either `ssuffix` or `sprefix` is allowed to be empty. For example, if `s = "abc "`, then `" " + "abc "`, `"a " + "bc "`, `"ab " + "c "` , and `"abc " + " "` are valid splits.

Return `true` _if it is possible to form_ _a palindrome string, otherwise return_ `false`.

**Notice** that `x + y` denotes the concatenation of strings `x` and `y`.

**Example 1:**

**Input:** a =  "x ", b =  "y "
**Output:** true
**Explaination:** If either a or b are palindromes the answer is true since you can split in the following way:
aprefix =  " ", asuffix =  "x "
bprefix =  " ", bsuffix =  "y "
Then, aprefix + bsuffix =  " " +  "y " =  "y ", which is a palindrome.

**Example 2:**

**Input:** a =  "xbdef ", b =  "xecab "
**Output:** false

**Example 3:**

**Input:** a =  "ulacfd ", b =  "jizalu "
**Output:** true
**Explaination:** Split them at index 3:
aprefix =  "ula ", asuffix =  "cfd "
bprefix =  "jiz ", bsuffix =  "alu "
Then, aprefix + bsuffix =  "ula " +  "alu " =  "ulaalu ", which is a palindrome.

**Constraints:**

*   `1 <= a.length, b.length <= 105`
*   `a.length == b.length`
*   `a` and `b` consist of lowercase English letters
Count Subtrees With Max Distance Between Cities

There are `n` cities numbered from `1` to `n`. You are given an array `edges` of size `n-1`, where `edges[i] = [ui, vi]` represents a bidirectional edge between cities `ui` and `vi`. There exists a unique path between each pair of cities. In other words, the cities form a **tree**.

A **subtree** is a subset of cities where every city is reachable from every other city in the subset, where the path between each pair passes through only the cities from the subset. Two subtrees are different if there is a city in one subtree that is not present in the other.

For each `d` from `1` to `n-1`, find the number of subtrees in which the **maximum distance** between any two cities in the subtree is equal to `d`.

Return _an array of size_ `n-1` _where the_ `dth` _element **(1-indexed)** is the number of subtrees in which the **maximum distance** between any two cities is equal to_ `d`.

**Notice** that the **distance** between the two cities is the number of edges in the path between them.

**Example 1:**

**Input:** n = 4, edges = \[\[1,2\],\[2,3\],\[2,4\]\]
**Output:** \[3,4,0\]
**Explanation:**
The subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.
The subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.
No subtree has two nodes where the max distance between them is 3.

**Example 2:**

**Input:** n = 2, edges = \[\[1,2\]\]
**Output:** \[1\]

**Example 3:**

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

**Constraints:**

*   `2 <= n <= 15`
*   `edges.length == n-1`
*   `edges[i].length == 2`
*   `1 <= ui, vi <= n`
*   All pairs `(ui, vi)` are distinct.