bowang0911/leetcode huggingface dataset:
Largest Color Value in a Directed Graph

There is a **directed graph** of `n` colored nodes and `m` edges. The nodes are numbered from `0` to `n - 1`.

You are given a string `colors` where `colors[i]` is a lowercase English letter representing the **color** of the `ith` node in this graph (**0-indexed**). You are also given a 2D array `edges` where `edges[j] = [aj, bj]` indicates that there is a **directed edge** from node `aj` to node `bj`.

A valid **path** in the graph is a sequence of nodes `x1 -> x2 -> x3 -> ... -> xk` such that there is a directed edge from `xi` to `xi+1` for every `1 <= i < k`. The **color value** of the path is the number of nodes that are colored the **most frequently** occurring color along that path.

Return _the **largest color value** of any valid path in the given graph, or_ `-1` _if the graph contains a cycle_.

**Example 1:**

**Input:** colors =  "abaca ", edges = \[\[0,1\],\[0,2\],\[2,3\],\[3,4\]\]
**Output:** 3
**Explanation:** The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored ` "a " (red in the above image)`.

**Example 2:**

**Input:** colors =  "a ", edges = \[\[0,0\]\]
**Output:** -1
**Explanation:** There is a cycle from 0 to 0.

**Constraints:**

*   `n == colors.length`
*   `m == edges.length`
*   `1 <= n <= 105`
*   `0 <= m <= 105`
*   `colors` consists of lowercase English letters.
*   `0 <= aj, bj < n`
Longest Word With All Prefixes

Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`.

*   For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`.

Return _the string described above. If there is more than one string with the same length, return the **lexicographically smallest** one, and if no string exists, return_ `" "`.

**Example 1:**

**Input:** words = \[ "k ", "ki ", "kir ", "kira ",  "kiran "\]
**Output:**  "kiran "
**Explanation:**  "kiran " has prefixes  "kira ",  "kir ",  "ki ", and  "k ", and all of them appear in words.

**Example 2:**

**Input:** words = \[ "a ",  "banana ",  "app ",  "appl ",  "ap ",  "apply ",  "apple "\]
**Output:**  "apple "
**Explanation:** Both  "apple " and  "apply " have all their prefixes in words.
However,  "apple " is lexicographically smaller, so we return that.

**Example 3:**

**Input:** words = \[ "abc ",  "bc ",  "ab ",  "qwe "\]
**Output:**  " "

**Constraints:**

*   `1 <= words.length <= 105`
*   `1 <= words[i].length <= 105`
*   `1 <= sum(words[i].length) <= 105`
Sorting the Sentence

A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.

A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence.

*   For example, the sentence `"This is a sentence "` can be shuffled as `"sentence4 a3 is2 This1 "` or `"is2 sentence4 This1 a3 "`.

Given a **shuffled sentence** `s` containing no more than `9` words, reconstruct and return _the original sentence_.

**Example 1:**

**Input:** s =  "is2 sentence4 This1 a3 "
**Output:**  "This is a sentence "
**Explanation:** Sort the words in s to their original positions  "This1 is2 a3 sentence4 ", then remove the numbers.

**Example 2:**

**Input:** s =  "Myself2 Me1 I4 and3 "
**Output:**  "Me Myself and I "
**Explanation:** Sort the words in s to their original positions  "Me1 Myself2 and3 I4 ", then remove the numbers.

**Constraints:**

*   `2 <= s.length <= 200`
*   `s` consists of lowercase and uppercase English letters, spaces, and digits from `1` to `9`.
*   The number of words in `s` is between `1` and `9`.
*   The words in `s` are separated by a single space.
*   `s` contains no leading or trailing spaces.

1\. All characters in a are strictly less than those in b (i.e., a\[i\] < b\[i\] for all i). 2. All characters in b are strictly less than those in a (i.e., a\[i\] > b\[i\] for all i). 3. All characters in a and b are the same (i.e., a\[i\] = b\[i\] for all i).
Incremental Memory Leak

You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.

At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more available memory** (or from the first memory stick if both have the same available memory). If neither stick has at least `i` bits of available memory, the program **crashes**.

Return _an array containing_ `[crashTime, memory1crash, memory2crash]`_, where_ `crashTime` _is the time (in seconds) when the program crashed and_ `memory1crash` _and_ `memory2crash` _are the available bits of memory in the first and second sticks respectively_.

**Example 1:**

**Input:** memory1 = 2, memory2 = 2
**Output:** \[3,1,0\]
**Explanation:** The memory is allocated as follows:
- At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.
- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.
- At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.

**Example 2:**

**Input:** memory1 = 8, memory2 = 11
**Output:** \[6,0,4\]
**Explanation:** The memory is allocated as follows:
- At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.
- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.
- At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.
- At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.
- At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.
- At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.

**Constraints:**

*   `0 <= memory1, memory2 <= 231 - 1`
Rotating the Box

You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following:

*   A stone `'#'`
*   A stationary obstacle `'*'`
*   Empty `'.'`

The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity **does not** affect the obstacles' positions, and the inertia from the box's rotation **does not** affect the stones' horizontal positions.

It is **guaranteed** that each stone in `box` rests on an obstacle, another stone, or the bottom of the box.

Return _an_ `n x m` _matrix representing the box after the rotation described above_.

**Example 1:**

**Input:** box = \[\[ "# ", ". ", "# "\]\]
**Output:** \[\[ ". "\],
         \[ "# "\],
         \[ "# "\]\]

**Example 2:**

**Input:** box = \[\[ "# ", ". ", "\* ", ". "\],
              \[ "# ", "# ", "\* ", ". "\]\]
**Output:** \[\[ "# ", ". "\],
         \[ "# ", "# "\],
         \[ "\* ", "\* "\],
         \[ ". ", ". "\]\]

**Example 3:**

**Input:** box = \[\[ "# ", "# ", "\* ", ". ", "\* ", ". "\],
              \[ "# ", "# ", "# ", "\* ", ". ", ". "\],
              \[ "# ", "# ", "# ", ". ", "# ", ". "\]\]
**Output:** \[\[ ". ", "# ", "# "\],
         \[ ". ", "# ", "# "\],
         \[ "# ", "# ", "\* "\],
         \[ "# ", "\* ", ". "\],
         \[ "# ", ". ", "\* "\],
         \[ "# ", ". ", ". "\]\]

**Constraints:**

*   `m == box.length`
*   `n == box[i].length`
*   `1 <= m, n <= 500`
*   `box[i][j]` is either `'#'`, `'*'`, or `'.'`.
Sum of Floored Pairs

Given an integer array `nums`, return the sum of `floor(nums[i] / nums[j])` for all pairs of indices `0 <= i, j < nums.length` in the array. Since the answer may be too large, return it **modulo** `109 + 7`.

The `floor()` function returns the integer part of the division.

**Example 1:**

**Input:** nums = \[2,5,9\]
**Output:** 10
**Explanation:**
floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0
floor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1
floor(5 / 2) = 2
floor(9 / 2) = 4
floor(9 / 5) = 1
We calculate the floor of the division for every pair of indices in the array then sum them up.

**Example 2:**

**Input:** nums = \[7,7,7,7,7,7,7\]
**Output:** 49

**Constraints:**

*   `1 <= nums.length <= 105`
*   `1 <= nums[i] <= 105`
Sum of All Subset XOR Totals

The **XOR total** of an array is defined as the bitwise `XOR` of **all its elements**, or `0` if the array is **empty**.

*   For example, the **XOR total** of the array `[2,5,6]` is `2 XOR 5 XOR 6 = 1`.

Given an array `nums`, return _the **sum** of all **XOR totals** for every **subset** of_ `nums`.

**Note:** Subsets with the **same** elements should be counted **multiple** times.

An array `a` is a **subset** of an array `b` if `a` can be obtained from `b` by deleting some (possibly zero) elements of `b`.

**Example 1:**

**Input:** nums = \[1,3\]
**Output:** 6
**Explanation:** The 4 subsets of \[1,3\] are:
- The empty subset has an XOR total of 0.
- \[1\] has an XOR total of 1.
- \[3\] has an XOR total of 3.
- \[1,3\] has an XOR total of 1 XOR 3 = 2.
0 + 1 + 3 + 2 = 6

**Example 2:**

**Input:** nums = \[5,1,6\]
**Output:** 28
**Explanation:** The 8 subsets of \[5,1,6\] are:
- The empty subset has an XOR total of 0.
- \[5\] has an XOR total of 5.
- \[1\] has an XOR total of 1.
- \[6\] has an XOR total of 6.
- \[5,1\] has an XOR total of 5 XOR 1 = 4.
- \[5,6\] has an XOR total of 5 XOR 6 = 3.
- \[1,6\] has an XOR total of 1 XOR 6 = 7.
- \[5,1,6\] has an XOR total of 5 XOR 1 XOR 6 = 2.
0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28

**Example 3:**

**Input:** nums = \[3,4,5,6,7,8\]
**Output:** 480
**Explanation:** The sum of all XOR totals for every subset is 480.

**Constraints:**

*   `1 <= nums.length <= 12`
*   `1 <= nums[i] <= 20`
Minimum Number of Swaps to Make the Binary String Alternating

Given a binary string `s`, return _the **minimum** number of character swaps to make it **alternating**, or_ `-1` _if it is impossible._

The string is called **alternating** if no two adjacent characters are equal. For example, the strings `"010 "` and `"1010 "` are alternating, while the string `"0100 "` is not.

Any two characters may be swapped, even if they are **not adjacent**.

**Example 1:**

**Input:** s =  "111000 "
**Output:** 1
**Explanation:** Swap positions 1 and 4:  "111000 " ->  "101010 "
The string is now alternating.

**Example 2:**

**Input:** s =  "010 "
**Output:** 0
**Explanation:** The string is already alternating, no swaps are needed.

**Example 3:**

**Input:** s =  "1110 "
**Output:** -1

**Constraints:**

*   `1 <= s.length <= 1000`
*   `s[i]` is either `'0'` or `'1'`.
Finding Pairs With a Certain Sum

You are given two integer arrays `nums1` and `nums2`. You are tasked to implement a data structure that supports queries of two types:

1.  **Add** a positive integer to an element of a given index in the array `nums2`.
2.  **Count** the number of pairs `(i, j)` such that `nums1[i] + nums2[j]` equals a given value (`0 <= i < nums1.length` and `0 <= j < nums2.length`).

Implement the `FindSumPairs` class:

*   `FindSumPairs(int[] nums1, int[] nums2)` Initializes the `FindSumPairs` object with two integer arrays `nums1` and `nums2`.
*   `void add(int index, int val)` Adds `val` to `nums2[index]`, i.e., apply `nums2[index] += val`.
*   `int count(int tot)` Returns the number of pairs `(i, j)` such that `nums1[i] + nums2[j] == tot`.

**Example 1:**

**Input**
\[ "FindSumPairs ",  "count ",  "add ",  "count ",  "count ",  "add ",  "add ",  "count "\]
\[\[\[1, 1, 2, 2, 2, 3\], \[1, 4, 5, 2, 5, 4\]\], \[7\], \[3, 2\], \[8\], \[4\], \[0, 1\], \[1, 1\], \[7\]\]
**Output**
\[null, 8, null, 2, 1, null, null, 11\]

**Explanation**
FindSumPairs findSumPairs = new FindSumPairs(\[1, 1, 2, 2, 2, 3\], \[1, 4, 5, 2, 5, 4\]);
findSumPairs.count(7);  // return 8; pairs (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) make 2 + 5 and pairs (5,1), (5,5) make 3 + 4
findSumPairs.add(3, 2); // now nums2 = \[1,4,5,**4**`,5,4`\]
findSumPairs.count(8);  // return 2; pairs (5,2), (5,4) make 3 + 5
findSumPairs.count(4);  // return 1; pair (5,0) makes 3 + 1
findSumPairs.add(0, 1); // now nums2 = \[**`2`**,4,5,4`,5,4`\]
findSumPairs.add(1, 1); // now nums2 = \[`2`,**5**,5,4`,5,4`\]
findSumPairs.count(7);  // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) make 2 + 5 and pairs (5,3), (5,5) make 3 + 4

**Constraints:**

*   `1 <= nums1.length <= 1000`
*   `1 <= nums2.length <= 105`
*   `1 <= nums1[i] <= 109`
*   `1 <= nums2[i] <= 105`
*   `0 <= index < nums2.length`
*   `1 <= val <= 105`
*   `1 <= tot <= 109`
*   At most `1000` calls are made to `add` and `count` **each**.
Number of Ways to Rearrange Sticks With K Sticks Visible

There are `n` uniquely-sized sticks whose lengths are integers from `1` to `n`. You want to arrange the sticks such that **exactly** `k` sticks are **visible** from the left. A stick is **visible** from the left if there are no **longer** sticks to the **left** of it.

*   For example, if the sticks are arranged `[1,3,2,5,4]`, then the sticks with lengths `1`, `3`, and `5` are visible from the left.

Given `n` and `k`, return _the **number** of such arrangements_. Since the answer may be large, return it **modulo** `109 + 7`.

**Example 1:**

**Input:** n = 3, k = 2
**Output:** 3
**Explanation:** \[1,3,2\], \[2,3,1\], and \[2,1,3\] are the only arrangements such that exactly 2 sticks are visible.
The visible sticks are underlined.

**Example 2:**

**Input:** n = 5, k = 5
**Output:** 1
**Explanation:** \[1,2,3,4,5\] is the only arrangement such that all 5 sticks are visible.
The visible sticks are underlined.

**Example 3:**

**Input:** n = 20, k = 11
**Output:** 647427950
**Explanation:** There are 647427950 (mod 109 \+ 7) ways to rearrange the sticks such that exactly 11 sticks are visible.

**Constraints:**

*   `1 <= n <= 1000`
*   `1 <= k <= n`
Product of Two Run-Length Encoded Arrays

**Run-length encoding** is a compression algorithm that allows for an integer array `nums` with many segments of **consecutive repeated** numbers to be represented by a (generally smaller) 2D array `encoded`. Each `encoded[i] = [vali, freqi]` describes the `ith` segment of repeated numbers in `nums` where `vali` is the value that is repeated `freqi` times.

*   For example, `nums = [1,1,1,2,2,2,2,2]` is represented by the **run-length encoded** array `encoded = [[1,3],[2,5]]`. Another way to read this is "three `1`'s followed by five `2`'s ".

The **product** of two run-length encoded arrays `encoded1` and `encoded2` can be calculated using the following steps:

1.  **Expand** both `encoded1` and `encoded2` into the full arrays `nums1` and `nums2` respectively.
2.  Create a new array `prodNums` of length `nums1.length` and set `prodNums[i] = nums1[i] * nums2[i]`.
3.  **Compress** `prodNums` into a run-length encoded array and return it.

You are given two **run-length encoded** arrays `encoded1` and `encoded2` representing full arrays `nums1` and `nums2` respectively. Both `nums1` and `nums2` have the **same length**. Each `encoded1[i] = [vali, freqi]` describes the `ith` segment of `nums1`, and each `encoded2[j] = [valj, freqj]` describes the `jth` segment of `nums2`.

Return _the **product** of_ `encoded1` _and_ `encoded2`.

**Note:** Compression should be done such that the run-length encoded array has the **minimum** possible length.

**Example 1:**

**Input:** encoded1 = \[\[1,3\],\[2,3\]\], encoded2 = \[\[6,3\],\[3,3\]\]
**Output:** \[\[6,6\]\]
**Explanation:** encoded1 expands to \[1,1,1,2,2,2\] and encoded2 expands to \[6,6,6,3,3,3\].
prodNums = \[6,6,6,6,6,6\], which is compressed into the run-length encoded array \[\[6,6\]\].

**Example 2:**

**Input:** encoded1 = \[\[1,3\],\[2,1\],\[3,2\]\], encoded2 = \[\[2,3\],\[3,3\]\]
**Output:** \[\[2,3\],\[6,1\],\[9,2\]\]
**Explanation:** encoded1 expands to \[1,1,1,2,3,3\] and encoded2 expands to \[2,2,2,3,3,3\].
prodNums = \[2,2,2,6,9,9\], which is compressed into the run-length encoded array \[\[2,3\],\[6,1\],\[9,2\]\].

**Constraints:**

*   `1 <= encoded1.length, encoded2.length <= 105`
*   `encoded1[i].length == 2`
*   `encoded2[j].length == 2`
*   `1 <= vali, freqi <= 104` for each `encoded1[i]`.
*   `1 <= valj, freqj <= 104` for each `encoded2[j]`.
*   The full arrays that `encoded1` and `encoded2` represent are the same length.
Longer Contiguous Segments of Ones than Zeros

Given a binary string `s`, return `true` _if the **longest** contiguous segment of_ `1`'_s is **strictly longer** than the **longest** contiguous segment of_ `0`'_s in_ `s`, or return `false` _otherwise_.

*   For example, in `s = "110100010 "` the longest continuous segment of `1`s has length `2`, and the longest continuous segment of `0`s has length `3`.

Note that if there are no `0`'s, then the longest continuous segment of `0`'s is considered to have a length `0`. The same applies if there is no `1`'s.

**Example 1:**

**Input:** s =  "1101 "
**Output:** true
**Explanation:**
The longest contiguous segment of 1s has length 2:  "1101 "
The longest contiguous segment of 0s has length 1:  "1101 "
The segment of 1s is longer, so return true.

**Example 2:**

**Input:** s =  "111000 "
**Output:** false
**Explanation:**
The longest contiguous segment of 1s has length 3:  "111000 "
The longest contiguous segment of 0s has length 3:  "111000 "
The segment of 1s is not longer, so return false.

**Example 3:**

**Input:** s =  "110100010 "
**Output:** false
**Explanation:**
The longest contiguous segment of 1s has length 2:  "110100010 "
The longest contiguous segment of 0s has length 3:  "110100010 "
The segment of 1s is not longer, so return false.

**Constraints:**

*   `1 <= s.length <= 100`
*   `s[i]` is either `'0'` or `'1'`.
Minimum Speed to Arrive on Time

You are given a floating-point number `hour`, representing the amount of time you have to reach the office. To commute to the office, you must take `n` trains in sequential order. You are also given an integer array `dist` of length `n`, where `dist[i]` describes the distance (in kilometers) of the `ith` train ride.

Each train can only depart at an integer hour, so you may need to wait in between each train ride.

*   For example, if the `1st` train ride takes `1.5` hours, you must wait for an additional `0.5` hours before you can depart on the `2nd` train ride at the 2 hour mark.

Return _the **minimum positive integer** speed **(in kilometers per hour)** that all the trains must travel at for you to reach the office on time, or_ `-1` _if it is impossible to be on time_.

Tests are generated such that the answer will not exceed `107` and `hour` will have **at most two digits after the decimal point**.

**Example 1:**

**Input:** dist = \[1,3,2\], hour = 6
**Output:** 1
**Explanation:** At speed 1:
- The first train ride takes 1/1 = 1 hour.
- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.
- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.
- You will arrive at exactly the 6 hour mark.

**Example 2:**

**Input:** dist = \[1,3,2\], hour = 2.7
**Output:** 3
**Explanation:** At speed 3:
- The first train ride takes 1/3 = 0.33333 hours.
- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.
- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.
- You will arrive at the 2.66667 hour mark.

**Example 3:**

**Input:** dist = \[1,3,2\], hour = 1.9
**Output:** -1
**Explanation:** It is impossible because the earliest the third train can depart is at the 2 hour mark.

**Constraints:**

*   `n == dist.length`
*   `1 <= n <= 105`
*   `1 <= dist[i] <= 105`
*   `1 <= hour <= 109`
*   There will be at most two digits after the decimal point in `hour`.
Jump Game VII

You are given a **0-indexed** binary string `s` and two integers `minJump` and `maxJump`. In the beginning, you are standing at index `0`, which is equal to `'0'`. You can move from index `i` to index `j` if the following conditions are fulfilled:

*   `i + minJump <= j <= min(i + maxJump, s.length - 1)`, and
*   `s[j] == '0'`.

Return `true` _if you can reach index_ `s.length - 1` _in_ `s`_, or_ `false` _otherwise._

**Example 1:**

**Input:** s =  "011010 ", minJump = 2, maxJump = 3
**Output:** true
**Explanation:**
In the first step, move from index 0 to index 3. 
In the second step, move from index 3 to index 5.

**Example 2:**

**Input:** s =  "01101110 ", minJump = 2, maxJump = 3
**Output:** false

**Constraints:**

*   `2 <= s.length <= 105`
*   `s[i]` is either `'0'` or `'1'`.
*   `s[0] == '0'`
*   `1 <= minJump <= maxJump < s.length`
Stone Game VIII

Alice and Bob take turns playing a game, with **Alice starting first**.

There are `n` stones arranged in a row. On each player's turn, while the number of stones is **more than one**, they will do the following:

1.  Choose an integer `x > 1`, and **remove** the leftmost `x` stones from the row.
2.  Add the **sum** of the **removed** stones' values to the player's score.
3.  Place a **new stone**, whose value is equal to that sum, on the left side of the row.

The game stops when **only** **one** stone is left in the row.

The **score difference** between Alice and Bob is `(Alice's score - Bob's score)`. Alice's goal is to **maximize** the score difference, and Bob's goal is the **minimize** the score difference.

Given an integer array `stones` of length `n` where `stones[i]` represents the value of the `ith` stone **from the left**, return _the **score difference** between Alice and Bob if they both play **optimally**._

**Example 1:**

**Input:** stones = \[-1,2,-3,4,-5\]
**Output:** 5
**Explanation:**
- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of
  value 2 on the left. stones = \[2,-5\].
- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on
  the left. stones = \[-3\].
The difference between their scores is 2 - (-3) = 5.

**Example 2:**

**Input:** stones = \[7,-6,5,10,5,-2,-6\]
**Output:** 13
**Explanation:**
- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a
  stone of value 13 on the left. stones = \[13\].
The difference between their scores is 13 - 0 = 13.

**Example 3:**

**Input:** stones = \[-10,-12\]
**Output:** -22
**Explanation:**
- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her
  score and places a stone of value -22 on the left. stones = \[-22\].
The difference between their scores is (-22) - 0 = -22.

**Constraints:**

*   `n == stones.length`
*   `2 <= n <= 105`
*   `-104 <= stones[i] <= 104`
Minimize Product Sum of Two Arrays

The **product sum** of two equal-length arrays `a` and `b` is equal to the sum of `a[i] * b[i]` for all `0 <= i < a.length` (**0-indexed**).

*   For example, if `a = [1,2,3,4]` and `b = [5,2,3,1]`, the **product sum** would be `1*5 + 2*2 + 3*3 + 4*1 = 22`.

Given two arrays `nums1` and `nums2` of length `n`, return _the **minimum product sum** if you are allowed to **rearrange** the **order** of the elements in_ `nums1`.

**Example 1:**

**Input:** nums1 = \[5,3,4,2\], nums2 = \[4,2,2,5\]
**Output:** 40
**Explanation:** We can rearrange nums1 to become \[3,5,4,2\]. The product sum of \[3,5,4,2\] and \[4,2,2,5\] is 3\*4 + 5\*2 + 4\*2 + 2\*5 = 40.

**Example 2:**

**Input:** nums1 = \[2,1,4,5,7\], nums2 = \[3,2,4,8,6\]
**Output:** 65
**Explanation:** We can rearrange nums1 to become \[5,7,4,1,2\]. The product sum of \[5,7,4,1,2\] and \[3,2,4,8,6\] is 5\*3 + 7\*2 + 4\*4 + 1\*8 + 2\*6 = 65.

**Constraints:**

*   `n == nums1.length == nums2.length`
*   `1 <= n <= 105`
*   `1 <= nums1[i], nums2[i] <= 100`