bowang0911/leetcode huggingface dataset:
Maximum Compatibility Score Sum

There is a survey that consists of `n` questions where each question's answer is either `0` (no) or `1` (yes).

The survey was given to `m` students numbered from `0` to `m - 1` and `m` mentors numbered from `0` to `m - 1`. The answers of the students are represented by a 2D integer array `students` where `students[i]` is an integer array that contains the answers of the `ith` student (**0-indexed**). The answers of the mentors are represented by a 2D integer array `mentors` where `mentors[j]` is an integer array that contains the answers of the `jth` mentor (**0-indexed**).

Each student will be assigned to **one** mentor, and each mentor will have **one** student assigned to them. The **compatibility score** of a student-mentor pair is the number of answers that are the same for both the student and the mentor.

*   For example, if the student's answers were `[1, 0, 1]` and the mentor's answers were `[0, 0, 1]`, then their compatibility score is 2 because only the second and the third answers are the same.

You are tasked with finding the optimal student-mentor pairings to **maximize** the **sum of the compatibility scores**.

Given `students` and `mentors`, return _the **maximum compatibility score sum** that can be achieved._

**Example 1:**

**Input:** students = \[\[1,1,0\],\[1,0,1\],\[0,0,1\]\], mentors = \[\[1,0,0\],\[0,0,1\],\[1,1,0\]\]
**Output:** 8
**Explanation:** We assign students to mentors in the following way:
- student 0 to mentor 2 with a compatibility score of 3.
- student 1 to mentor 0 with a compatibility score of 2.
- student 2 to mentor 1 with a compatibility score of 3.
The compatibility score sum is 3 + 2 + 3 = 8.

**Example 2:**

**Input:** students = \[\[0,0\],\[0,0\],\[0,0\]\], mentors = \[\[1,1\],\[1,1\],\[1,1\]\]
**Output:** 0
**Explanation:** The compatibility score of any student-mentor pair is 0.

**Constraints:**

*   `m == students.length == mentors.length`
*   `n == students[i].length == mentors[j].length`
*   `1 <= m, n <= 8`
*   `students[i][k]` is either `0` or `1`.
*   `mentors[j][k]` is either `0` or `1`.
Delete Duplicate Folders in System

Due to a bug, there are many duplicate folders in a file system. You are given a 2D array `paths`, where `paths[i]` is an array representing an absolute path to the `ith` folder in the file system.

*   For example, `[ "one ", "two ", "three "]` represents the path `"/one/two/three "`.

Two folders (not necessarily on the same level) are **identical** if they contain the **same non-empty** set of identical subfolders and underlying subfolder structure. The folders **do not** need to be at the root level to be identical. If two or more folders are **identical**, then **mark** the folders as well as all their subfolders.

*   For example, folders `"/a "` and `"/b "` in the file structure below are identical. They (as well as their subfolders) should **all** be marked:
    *   `/a`
    *   `/a/x`
    *   `/a/x/y`
    *   `/a/z`
    *   `/b`
    *   `/b/x`
    *   `/b/x/y`
    *   `/b/z`
*   However, if the file structure also included the path `"/b/w "`, then the folders `"/a "` and `"/b "` would not be identical. Note that `"/a/x "` and `"/b/x "` would still be considered identical even with the added folder.

Once all the identical folders and their subfolders have been marked, the file system will **delete** all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.

Return _the 2D array_ `ans` _containing the paths of the **remaining** folders after deleting all the marked folders. The paths may be returned in **any** order_.

**Example 1:**

**Input:** paths = \[\[ "a "\],\[ "c "\],\[ "d "\],\[ "a ", "b "\],\[ "c ", "b "\],\[ "d ", "a "\]\]
**Output:** \[\[ "d "\],\[ "d ", "a "\]\]
**Explanation:** The file structure is as shown.
Folders  "/a " and  "/c " (and their subfolders) are marked for deletion because they both contain an empty
folder named  "b ".

**Example 2:**

**Input:** paths = \[\[ "a "\],\[ "c "\],\[ "a ", "b "\],\[ "c ", "b "\],\[ "a ", "b ", "x "\],\[ "a ", "b ", "x ", "y "\],\[ "w "\],\[ "w ", "y "\]\]
**Output:** \[\[ "c "\],\[ "c ", "b "\],\[ "a "\],\[ "a ", "b "\]\]
**Explanation:** The file structure is as shown. 
Folders  "/a/b/x " and  "/w " (and their subfolders) are marked for deletion because they both contain an empty folder named  "y ".
Note that folders  "/a " and  "/c " are identical after the deletion, but they are not deleted because they were not marked beforehand.

**Example 3:**

**Input:** paths = \[\[ "a ", "b "\],\[ "c ", "d "\],\[ "c "\],\[ "a "\]\]
**Output:** \[\[ "c "\],\[ "c ", "d "\],\[ "a "\],\[ "a ", "b "\]\]
**Explanation:** All folders are unique in the file system.
Note that the returned array can be in a different order as the order does not matter.

**Constraints:**

*   `1 <= paths.length <= 2 * 104`
*   `1 <= paths[i].length <= 500`
*   `1 <= paths[i][j].length <= 10`
*   `1 <= sum(paths[i][j].length) <= 2 * 105`
*   `path[i][j]` consists of lowercase English letters.
*   No two paths lead to the same folder.
*   For any folder not at the root level, its parent folder will also be in the input.
Maximum of Minimum Values in All Subarrays

You are given an integer array `nums` of size `n`. You are asked to solve `n` queries for each integer `i` in the range `0 <= i < n`.

To solve the `ith` query:

1.  Find the **minimum value** in each possible subarray of size `i + 1` of the array `nums`.
2.  Find the **maximum** of those minimum values. This maximum is the **answer** to the query.

Return _a **0-indexed** integer array_ `ans` _of size_ `n` _such that_ `ans[i]` _is the answer to the_ `ith` _query_.

A **subarray** is a contiguous sequence of elements in an array.

**Example 1:**

**Input:** nums = \[0,1,2,4\]
**Output:** \[4,2,1,0\]
**Explanation:**
i=0:
- The subarrays of size 1 are \[0\], \[1\], \[2\], \[4\]. The minimum values are 0, 1, 2, 4.
- The maximum of the minimum values is 4.
i=1:
- The subarrays of size 2 are \[0,1\], \[1,2\], \[2,4\]. The minimum values are 0, 1, 2.
- The maximum of the minimum values is 2.
i=2:
- The subarrays of size 3 are \[0,1,2\], \[1,2,4\]. The minimum values are 0, 1.
- The maximum of the minimum values is 1.
i=3:
- There is one subarray of size 4, which is \[0,1,2,4\]. The minimum value is 0.
- There is only one value, so the maximum is 0.

**Example 2:**

**Input:** nums = \[10,20,50,10\]
**Output:** \[50,20,10,10\]
**Explanation:**
i=0:
- The subarrays of size 1 are \[10\], \[20\], \[50\], \[10\]. The minimum values are 10, 20, 50, 10.
- The maximum of the minimum values is 50.
i=1:
- The subarrays of size 2 are \[10,20\], \[20,50\], \[50,10\]. The minimum values are 10, 20, 10.
- The maximum of the minimum values is 20.
i=2:
- The subarrays of size 3 are \[10,20,50\], \[20,50,10\]. The minimum values are 10, 10.
- The maximum of the minimum values is 10.
i=3:
- There is one subarray of size 4, which is \[10,20,50,10\]. The minimum value is 10.
- There is only one value, so the maximum is 10.

**Constraints:**

*   `n == nums.length`
*   `1 <= n <= 105`
*   `0 <= nums[i] <= 109`
Three Divisors

Given an integer `n`, return `true` _if_ `n` _has **exactly three positive divisors**. Otherwise, return_ `false`.

An integer `m` is a **divisor** of `n` if there exists an integer `k` such that `n = k * m`.

**Example 1:**

**Input:** n = 2
**Output:** false
**Explantion:** 2 has only two divisors: 1 and 2.

**Example 2:**

**Input:** n = 4
**Output:** true
**Explantion:** 4 has three divisors: 1, 2, and 4.

**Constraints:**

*   `1 <= n <= 104`
Maximum Number of Weeks for Which You Can Work

There are `n` projects numbered from `0` to `n - 1`. You are given an integer array `milestones` where each `milestones[i]` denotes the number of milestones the `ith` project has.

You can work on the projects following these two rules:

*   Every week, you will finish **exactly one** milestone of **one** project. You **must** work every week.
*   You **cannot** work on two milestones from the same project for two **consecutive** weeks.

Once all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will **stop working**. Note that you may not be able to finish every project's milestones due to these constraints.

Return _the **maximum** number of weeks you would be able to work on the projects without violating the rules mentioned above_.

**Example 1:**

**Input:** milestones = \[1,2,3\]
**Output:** 6
**Explanation:** One possible scenario is:
​​​​- During the 1st week, you will work on a milestone of project 0.
- During the 2nd week, you will work on a milestone of project 2.
- During the 3rd week, you will work on a milestone of project 1.
- During the 4th week, you will work on a milestone of project 2.
- During the 5th week, you will work on a milestone of project 1.
- During the 6th week, you will work on a milestone of project 2.
The total number of weeks is 6.

**Example 2:**

**Input:** milestones = \[5,2,1\]
**Output:** 7
**Explanation:** One possible scenario is:
- During the 1st week, you will work on a milestone of project 0.
- During the 2nd week, you will work on a milestone of project 1.
- During the 3rd week, you will work on a milestone of project 0.
- During the 4th week, you will work on a milestone of project 1.
- During the 5th week, you will work on a milestone of project 0.
- During the 6th week, you will work on a milestone of project 2.
- During the 7th week, you will work on a milestone of project 0.
The total number of weeks is 7.
Note that you cannot work on the last milestone of project 0 on 8th week because it would violate the rules.
Thus, one milestone in project 0 will remain unfinished.

**Constraints:**

*   `n == milestones.length`
*   `1 <= n <= 105`
*   `1 <= milestones[i] <= 109`
Minimum Garden Perimeter to Collect Enough Apples

In a garden represented as an infinite 2D grid, there is an apple tree planted at **every** integer coordinate. The apple tree planted at an integer coordinate `(i, j)` has `|i| + |j|` apples growing on it.

You will buy an axis-aligned **square plot** of land that is centered at `(0, 0)`.

Given an integer `neededApples`, return _the **minimum perimeter** of a plot such that **at least**_ `neededApples` _apples are **inside or on** the perimeter of that plot_.

The value of `|x|` is defined as:

*   `x` if `x >= 0`
*   `-x` if `x < 0`

**Example 1:**

**Input:** neededApples = 1
**Output:** 8
**Explanation:** A square plot of side length 1 does not contain any apples.
However, a square plot of side length 2 has 12 apples inside (as depicted in the image above).
The perimeter is 2 \* 4 = 8.

**Example 2:**

**Input:** neededApples = 13
**Output:** 16

**Example 3:**

**Input:** neededApples = 1000000000
**Output:** 5040

**Constraints:**

*   `1 <= neededApples <= 1015`
Count Number of Special Subsequences

A sequence is **special** if it consists of a **positive** number of `0`s, followed by a **positive** number of `1`s, then a **positive** number of `2`s.

*   For example, `[0,1,2]` and `[0,0,1,1,1,2]` are special.
*   In contrast, `[2,1,0]`, `[1]`, and `[0,1,2,0]` are not special.

Given an array `nums` (consisting of **only** integers `0`, `1`, and `2`), return _the **number of different subsequences** that are special_. Since the answer may be very large, **return it modulo** `109 + 7`.

A **subsequence** of an array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Two subsequences are **different** if the **set of indices** chosen are different.

**Example 1:**

**Input:** nums = \[0,1,2,2\]
**Output:** 3
**Explanation:** The special subsequences are bolded \[**0**,**1**,**2**,2\], \[**0**,**1**,2,**2**\], and \[**0**,**1**,**2**,**2**\].

**Example 2:**

**Input:** nums = \[2,2,0,0\]
**Output:** 0
**Explanation:** There are no special subsequences in \[2,2,0,0\].

**Example 3:**

**Input:** nums = \[0,1,2,0,1,2\]
**Output:** 7
**Explanation:** The special subsequences are bolded:
- \[**0**,**1**,**2**,0,1,2\]
- \[**0**,**1**,2,0,1,**2**\]
- \[**0**,**1**,**2**,0,1,**2**\]
- \[**0**,**1**,2,0,**1**,**2**\]
- \[**0**,1,2,**0**,**1**,**2**\]
- \[**0**,1,2,0,**1**,**2**\]
- \[0,1,2,**0**,**1**,**2**\]

**Constraints:**

*   `1 <= nums.length <= 105`
*   `0 <= nums[i] <= 2`
Minimum Time For K Virus Variants to Spread

There are `n` **unique** virus variants in an infinite 2D grid. You are given a 2D array `points`, where `points[i] = [xi, yi]` represents a virus originating at `(xi, yi)` on day `0`. Note that it is possible for **multiple** virus variants to originate at the **same** point.

Every day, each cell infected with a virus variant will spread the virus to **all** neighboring points in the **four** cardinal directions (i.e. up, down, left, and right). If a cell has multiple variants, all the variants will spread without interfering with each other.

Given an integer `k`, return _the **minimum integer** number of days for **any** point to contain **at least**_ `k` _of the unique virus variants_.

**Example 1:**

**Input:** points = \[\[1,1\],\[6,1\]\], k = 2
**Output:** 3
**Explanation:** On day 3, points (3,1) and (4,1) will contain both virus variants. Note that these are not the only points that will contain both virus variants.

**Example 2:**

**Input:** points = \[\[3,3\],\[1,2\],\[9,2\]\], k = 2
**Output:** 2
**Explanation:** On day 2, points (1,3), (2,3), (2,2), and (3,2) will contain the first two viruses. Note that these are not the only points that will contain both virus variants.

**Example 3:**

**Input:** points = \[\[3,3\],\[1,2\],\[9,2\]\], k = 3
**Output:** 4
**Explanation:** On day 4, the point (5,2) will contain all 3 viruses. Note that this is not the only point that will contain all 3 virus variants.

**Constraints:**

*   `n == points.length`
*   `2 <= n <= 50`
*   `points[i].length == 2`
*   `1 <= xi, yi <= 100`
*   `2 <= k <= n`
Delete Characters to Make Fancy String

A **fancy string** is a string where no **three** **consecutive** characters are equal.

Given a string `s`, delete the **minimum** possible number of characters from `s` to make it **fancy**.

Return _the final string after the deletion_. It can be shown that the answer will always be **unique**.

**Example 1:**

**Input:** s =  "leeetcode "
**Output:**  "leetcode "
**Explanation:**
Remove an 'e' from the first group of 'e's to create  "leetcode ".
No three consecutive characters are equal, so return  "leetcode ".

**Example 2:**

**Input:** s =  "aaabaaaa "
**Output:**  "aabaa "
**Explanation:**
Remove an 'a' from the first group of 'a's to create  "aabaaaa ".
Remove two 'a's from the second group of 'a's to create  "aabaa ".
No three consecutive characters are equal, so return  "aabaa ".

**Example 3:**

**Input:** s =  "aab "
**Output:**  "aab "
**Explanation:** No three consecutive characters are equal, so return  "aab ".

**Constraints:**

*   `1 <= s.length <= 105`
*   `s` consists only of lowercase English letters.
Check if Move is Legal

You are given a **0-indexed** `8 x 8` grid `board`, where `board[r][c]` represents the cell `(r, c)` on a game board. On the board, free cells are represented by `'.'`, white cells are represented by `'W'`, and black cells are represented by `'B'`.

Each move in this game consists of choosing a free cell and changing it to the color you are playing as (either white or black). However, a move is only **legal** if, after changing it, the cell becomes the **endpoint of a good line** (horizontal, vertical, or diagonal).

A **good line** is a line of **three or more cells (including the endpoints)** where the endpoints of the line are **one color**, and the remaining cells in the middle are the **opposite color** (no cells in the line are free). You can find examples for good lines in the figure below:

Given two integers `rMove` and `cMove` and a character `color` representing the color you are playing as (white or black), return `true` _if changing cell_ `(rMove, cMove)` _to color_ `color` _is a **legal** move, or_ `false` _if it is not legal_.

**Example 1:**

**Input:** board = \[\[ ". ", ". ", ". ", "B ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", "W ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", "W ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", "W ", ". ", ". ", ". ", ". "\],\[ "W ", "B ", "B ", ". ", "W ", "W ", "W ", "B "\],\[ ". ", ". ", ". ", "B ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", "B ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", "W ", ". ", ". ", ". ", ". "\]\], rMove = 4, cMove = 3, color =  "B "
**Output:** true
**Explanation:** '.', 'W', and 'B' are represented by the colors blue, white, and black respectively, and cell (rMove, cMove) is marked with an 'X'.
The two good lines with the chosen cell as an endpoint are annotated above with the red rectangles.

**Example 2:**

**Input:** board = \[\[ ". ", ". ", ". ", ". ", ". ", ". ", ". ", ". "\],\[ ". ", "B ", ". ", ". ", "W ", ". ", ". ", ". "\],\[ ". ", ". ", "W ", ". ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", "W ", "B ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", ". ", ". ", ". ", ". ", ". "\],\[ ". ", ". ", ". ", ". ", "B ", "W ", ". ", ". "\],\[ ". ", ". ", ". ", ". ", ". ", ". ", "W ", ". "\],\[ ". ", ". ", ". ", ". ", ". ", ". ", ". ", "B "\]\], rMove = 4, cMove = 4, color =  "W "
**Output:** false
**Explanation:** While there are good lines with the chosen cell as a middle cell, there are no good lines with the chosen cell as an endpoint.

**Constraints:**

*   `board.length == board[r].length == 8`
*   `0 <= rMove, cMove < 8`
*   `board[rMove][cMove] == '.'`
*   `color` is either `'B'` or `'W'`.
Minimum Total Space Wasted With K Resizing Operations

You are currently designing a dynamic array. You are given a **0-indexed** integer array `nums`, where `nums[i]` is the number of elements that will be in the array at time `i`. In addition, you are given an integer `k`, the **maximum** number of times you can **resize** the array (to **any** size).

The size of the array at time `t`, `sizet`, must be at least `nums[t]` because there needs to be enough space in the array to hold all the elements. The **space wasted** at time `t` is defined as `sizet - nums[t]`, and the **total** space wasted is the **sum** of the space wasted across every time `t` where `0 <= t < nums.length`.

Return _the **minimum** **total space wasted** if you can resize the array at most_ `k` _times_.

**Note:** The array can have **any size** at the start and does **not** count towards the number of resizing operations.

**Example 1:**

**Input:** nums = \[10,20\], k = 0
**Output:** 10
**Explanation:** size = \[20,20\].
We can set the initial size to be 20.
The total wasted space is (20 - 10) + (20 - 20) = 10.

**Example 2:**

**Input:** nums = \[10,20,30\], k = 1
**Output:** 10
**Explanation:** size = \[20,20,30\].
We can set the initial size to be 20 and resize to 30 at time 2. 
The total wasted space is (20 - 10) + (20 - 20) + (30 - 30) = 10.

**Example 3:**

**Input:** nums = \[10,20,15,30,20\], k = 2
**Output:** 15
**Explanation:** size = \[10,20,20,30,30\].
We can set the initial size to 10, resize to 20 at time 1, and resize to 30 at time 3.
The total wasted space is (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - 20) = 15.

**Constraints:**

*   `1 <= nums.length <= 200`
*   `1 <= nums[i] <= 106`
*   `0 <= k <= nums.length - 1`
Maximum Product of the Length of Two Palindromic Substrings

You are given a **0-indexed** string `s` and are tasked with finding two **non-intersecting palindromic** substrings of **odd** length such that the product of their lengths is maximized.

More formally, you want to choose four integers `i`, `j`, `k`, `l` such that `0 <= i <= j < k <= l < s.length` and both the substrings `s[i...j]` and `s[k...l]` are palindromes and have odd lengths. `s[i...j]` denotes a substring from index `i` to index `j` **inclusive**.

Return _the **maximum** possible product of the lengths of the two non-intersecting palindromic substrings._

A **palindrome** is a string that is the same forward and backward. A **substring** is a contiguous sequence of characters in a string.

**Example 1:**

**Input:** s =  "ababbb "
**Output:** 9
**Explanation:** Substrings  "aba " and  "bbb " are palindromes with odd length. product = 3 \* 3 = 9.

**Example 2:**

**Input:** s =  "zaaaxbbby "
**Output:** 9
**Explanation:** Substrings  "aaa " and  "bbb " are palindromes with odd length. product = 3 \* 3 = 9.

**Constraints:**

*   `2 <= s.length <= 105`
*   `s` consists of lowercase English letters.
Check If String Is a Prefix of Array

Given a string `s` and an array of strings `words`, determine whether `s` is a **prefix string** of `words`.

A string `s` is a **prefix string** of `words` if `s` can be made by concatenating the first `k` strings in `words` for some **positive** `k` no larger than `words.length`.

Return `true` _if_ `s` _is a **prefix string** of_ `words`_, or_ `false` _otherwise_.

**Example 1:**

**Input:** s =  "iloveleetcode ", words = \[ "i ", "love ", "leetcode ", "apples "\]
**Output:** true
**Explanation:**
s can be made by concatenating  "i ",  "love ", and  "leetcode " together.

**Example 2:**

**Input:** s =  "iloveleetcode ", words = \[ "apples ", "i ", "love ", "leetcode "\]
**Output:** false
**Explanation:**
It is impossible to make s using a prefix of arr.

**Constraints:**

*   `1 <= words.length <= 100`
*   `1 <= words[i].length <= 20`
*   `1 <= s.length <= 1000`
*   `words[i]` and `s` consist of only lowercase English letters.
Remove Stones to Minimize the Total

You are given a **0-indexed** integer array `piles`, where `piles[i]` represents the number of stones in the `ith` pile, and an integer `k`. You should apply the following operation **exactly** `k` times:

*   Choose any `piles[i]` and **remove** `floor(piles[i] / 2)` stones from it.

**Notice** that you can apply the operation on the **same** pile more than once.

Return _the **minimum** possible total number of stones remaining after applying the_ `k` _operations_.

`floor(x)` is the **greatest** integer that is **smaller** than or **equal** to `x` (i.e., rounds `x` down).

**Example 1:**

**Input:** piles = \[5,4,9\], k = 2
**Output:** 12
**Explanation:** Steps of a possible scenario are:
- Apply the operation on pile 2. The resulting piles are \[5,4,5\].
- Apply the operation on pile 0. The resulting piles are \[3,4,5\].
The total number of stones in \[3,4,5\] is 12.

**Example 2:**

**Input:** piles = \[4,3,6,7\], k = 3
**Output:** 12
**Explanation:** Steps of a possible scenario are:
- Apply the operation on pile 2. The resulting piles are \[4,3,3,7\].
- Apply the operation on pile 3. The resulting piles are \[4,3,3,4\].
- Apply the operation on pile 0. The resulting piles are \[2,3,3,4\].
The total number of stones in \[2,3,3,4\] is 12.

**Constraints:**

*   `1 <= piles.length <= 105`
*   `1 <= piles[i] <= 104`
*   `1 <= k <= 105`