bowang0911/leetcode huggingface dataset:
Design Front Middle Back Queue

Design a queue that supports `push` and `pop` operations in the front, middle, and back.

Implement the `FrontMiddleBack` class:

*   `FrontMiddleBack()` Initializes the queue.
*   `void pushFront(int val)` Adds `val` to the **front** of the queue.
*   `void pushMiddle(int val)` Adds `val` to the **middle** of the queue.
*   `void pushBack(int val)` Adds `val` to the **back** of the queue.
*   `int popFront()` Removes the **front** element of the queue and returns it. If the queue is empty, return `-1`.
*   `int popMiddle()` Removes the **middle** element of the queue and returns it. If the queue is empty, return `-1`.
*   `int popBack()` Removes the **back** element of the queue and returns it. If the queue is empty, return `-1`.

**Notice** that when there are **two** middle position choices, the operation is performed on the **frontmost** middle position choice. For example:

*   Pushing `6` into the middle of `[1, 2, 3, 4, 5]` results in `[1, 2, 6, 3, 4, 5]`.
*   Popping the middle from `[1, 2, 3, 4, 5, 6]` returns `3` and results in `[1, 2, 4, 5, 6]`.

**Example 1:**

**Input:**
\[ "FrontMiddleBackQueue ",  "pushFront ",  "pushBack ",  "pushMiddle ",  "pushMiddle ",  "popFront ",  "popMiddle ",  "popMiddle ",  "popBack ",  "popFront "\]
\[\[\], \[1\], \[2\], \[3\], \[4\], \[\], \[\], \[\], \[\], \[\]\]
**Output:**
\[null, null, null, null, null, 1, 3, 4, 2, -1\]

**Explanation:**
FrontMiddleBackQueue q = new FrontMiddleBackQueue();
q.pushFront(1);   // \[1\]
q.pushBack(2);    // \[1, 2\]
q.pushMiddle(3);  // \[1, 3, 2\]
q.pushMiddle(4);  // \[1, 4, 3, 2\]
q.popFront();     // return 1 -> \[4, 3, 2\]
q.popMiddle();    // return 3 -> \[4, 2\]
q.popMiddle();    // return 4 -> \[2\]
q.popBack();      // return 2 -> \[\]
q.popFront();     // return -1 -> \[\] (The queue is empty)

**Constraints:**

*   `1 <= val <= 109`
*   At most `1000` calls will be made to `pushFront`, `pushMiddle`, `pushBack`, `popFront`, `popMiddle`, and `popBack`.
Minimum Number of Removals to Make Mountain Array

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

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

Given an integer array `nums`​​​, return _the **minimum** number of elements to remove to make_ `nums_​​​_` _a **mountain array**._

**Example 1:**

**Input:** nums = \[1,3,1\]
**Output:** 0
**Explanation:** The array itself is a mountain array so we do not need to remove any elements.

**Example 2:**

**Input:** nums = \[2,1,1,5,6,2,3,1\]
**Output:** 3
**Explanation:** One solution is to remove the elements at indices 0, 1, and 5, making the array nums = \[1,5,6,3,1\].

**Constraints:**

*   `3 <= nums.length <= 1000`
*   `1 <= nums[i] <= 109`
*   It is guaranteed that you can make a mountain array out of `nums`.
Richest Customer Wealth

You are given an `m x n` integer grid `accounts` where `accounts[i][j]` is the amount of money the `i​​​​​​​​​​​th​​​​` customer has in the `j​​​​​​​​​​​th`​​​​ bank. Return _the **wealth** that the richest customer has._

A customer's **wealth** is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum **wealth**.

**Example 1:**

**Input:** accounts = \[\[1,2,3\],\[3,2,1\]\]
**Output:** 6
**Explanation****:**
`1st customer has wealth = 1 + 2 + 3 = 6`
`2nd customer has wealth = 3 + 2 + 1 = 6`
Both customers are considered the richest with a wealth of 6 each, so return 6.

**Example 2:**

**Input:** accounts = \[\[1,5\],\[7,3\],\[3,5\]\]
**Output:** 10
**Explanation**: 
1st customer has wealth = 6
2nd customer has wealth = 10 
3rd customer has wealth = 8
The 2nd customer is the richest with a wealth of 10.

**Example 3:**

**Input:** accounts = \[\[2,8,7\],\[7,1,3\],\[1,9,5\]\]
**Output:** 17

**Constraints:**

*   `m == accounts.length`
*   `n == accounts[i].length`
*   `1 <= m, n <= 50`
*   `1 <= accounts[i][j] <= 100`
Find the Most Competitive Subsequence

Given an integer array `nums` and a positive integer `k`, return _the most **competitive** subsequence of_ `nums` _of size_ `k`.

An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.

We define that a subsequence `a` is more **competitive** than a subsequence `b` (of the same length) if in the first position where `a` and `b` differ, subsequence `a` has a number **less** than the corresponding number in `b`. For example, `[1,3,4]` is more competitive than `[1,3,5]` because the first position they differ is at the final number, and `4` is less than `5`.

**Example 1:**

**Input:** nums = \[3,5,2,6\], k = 2
**Output:** \[2,6\]
**Explanation:** Among the set of every possible subsequence: {\[3,5\], \[3,2\], \[3,6\], \[5,2\], \[5,6\], \[2,6\]}, \[2,6\] is the most competitive.

**Example 2:**

**Input:** nums = \[2,4,3,3,5,4,9,6\], k = 4
**Output:** \[2,3,3,4\]

**Constraints:**

*   `1 <= nums.length <= 105`
*   `0 <= nums[i] <= 109`
*   `1 <= k <= nums.length`
Minimum Moves to Make Array Complementary

You are given an integer array `nums` of **even** length `n` and an integer `limit`. In one move, you can replace any integer from `nums` with another integer between `1` and `limit`, inclusive.

The array `nums` is **complementary** if for all indices `i` (**0-indexed**), `nums[i] + nums[n - 1 - i]` equals the same number. For example, the array `[1,2,3,4]` is complementary because for all indices `i`, `nums[i] + nums[n - 1 - i] = 5`.

Return the _**minimum** number of moves required to make_ `nums` _**complementary**_.

**Example 1:**

**Input:** nums = \[1,2,4,3\], limit = 4
**Output:** 1
**Explanation:** In 1 move, you can change nums to \[1,2,2,3\] (underlined elements are changed).
nums\[0\] + nums\[3\] = 1 + 3 = 4.
nums\[1\] + nums\[2\] = 2 + 2 = 4.
nums\[2\] + nums\[1\] = 2 + 2 = 4.
nums\[3\] + nums\[0\] = 3 + 1 = 4.
Therefore, nums\[i\] + nums\[n-1-i\] = 4 for every i, so nums is complementary.

**Example 2:**

**Input:** nums = \[1,2,2,1\], limit = 2
**Output:** 2
**Explanation:** In 2 moves, you can change nums to \[2,2,2,2\]. You cannot change any number to 3 since 3 > limit.

**Example 3:**

**Input:** nums = \[1,2,1,2\], limit = 2
**Output:** 0
**Explanation:** nums is already complementary.

**Constraints:**

*   `n == nums.length`
*   `2 <= n <= 105`
*   `1 <= nums[i] <= limit <= 105`
*   `n` is even.
Minimize Deviation in Array

You are given an array `nums` of `n` positive integers.

You can perform two types of operations on any element of the array any number of times:

*   If the element is **even**, **divide** it by `2`.
    *   For example, if the array is `[1,2,3,4]`, then you can do this operation on the last element, and the array will be `[1,2,3,2].`
*   If the element is **odd**, **multiply** it by `2`.
    *   For example, if the array is `[1,2,3,4]`, then you can do this operation on the first element, and the array will be `[2,2,3,4].`

The **deviation** of the array is the **maximum difference** between any two elements in the array.

Return _the **minimum deviation** the array can have after performing some number of operations._

**Example 1:**

**Input:** nums = \[1,2,3,4\]
**Output:** 1
**Explanation:** You can transform the array to \[1,2,3,2\], then to \[2,2,3,2\], then the deviation will be 3 - 2 = 1.

**Example 2:**

**Input:** nums = \[4,1,5,20,3\]
**Output:** 3
**Explanation:** You can transform the array after two operations to \[4,2,5,5,3\], then the deviation will be 5 - 2 = 3.

**Example 3:**

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

**Constraints:**

*   `n == nums.length`
*   `2 <= n <= 5 * 104`
*   `1 <= nums[i] <= 109`
Lowest Common Ancestor of a Binary Tree IV

Given the `root` of a binary tree and an array of `TreeNode` objects `nodes`, return _the lowest common ancestor (LCA) of **all the nodes** in_ `nodes`. All the nodes will exist in the tree, and all values of the tree's nodes are **unique**.

Extending the **[definition of LCA on Wikipedia](https://en.wikipedia.org/wiki/Lowest_common_ancestor)**: "The lowest common ancestor of `n` nodes `p1`, `p2`, ..., `pn` in a binary tree `T` is the lowest node that has every `pi` as a **descendant** (where we allow **a node to be a descendant of itself**) for every valid `i` ". A **descendant** of a node `x` is a node `y` that is on the path from node `x` to some leaf node.

**Example 1:**

**Input:** root = \[3,5,1,6,2,0,8,null,null,7,4\], nodes = \[4,7\]
**Output:** 2
**Explanation:** The lowest common ancestor of nodes 4 and 7 is node 2.

**Example 2:**

**Input:** root = \[3,5,1,6,2,0,8,null,null,7,4\], nodes = \[1\]
**Output:** 1
**Explanation:** The lowest common ancestor of a single node is the node itself.

**Example 3:**

**Input:** root = \[3,5,1,6,2,0,8,null,null,7,4\], nodes = \[7,6,2,4\]
**Output:** 5
**Explanation:** The lowest common ancestor of the nodes 7, 6, 2, and 4 is node 5.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   `-109 <= Node.val <= 109`
*   All `Node.val` are **unique**.
*   All `nodes[i]` will exist in the tree.
*   All `nodes[i]` are distinct.
Goal Parser Interpretation

You own a **Goal Parser** that can interpret a string `command`. The `command` consists of an alphabet of `"G "`, `"() "` and/or `"(al) "` in some order. The Goal Parser will interpret `"G "` as the string `"G "`, `"() "` as the string `"o "`, and `"(al) "` as the string `"al "`. The interpreted strings are then concatenated in the original order.

Given the string `command`, return _the **Goal Parser**'s interpretation of_ `command`.

**Example 1:**

**Input:** command =  "G()(al) "
**Output:**  "Goal "
**Explanation:** The Goal Parser interprets the command as follows:
G -> G
() -> o
(al) -> al
The final concatenated result is  "Goal ".

**Example 2:**

**Input:** command =  "G()()()()(al) "
**Output:**  "Gooooal "

**Example 3:**

**Input:** command =  "(al)G(al)()()G "
**Output:**  "alGalooG "

**Constraints:**

*   `1 <= command.length <= 100`
*   `command` consists of `"G "`, `"() "`, and/or `"(al) "` in some order.
Max Number of K-Sum Pairs

You are given an integer array `nums` and an integer `k`.

In one operation, you can pick two numbers from the array whose sum equals `k` and remove them from the array.

Return _the maximum number of operations you can perform on the array_.

**Example 1:**

**Input:** nums = \[1,2,3,4\], k = 5
**Output:** 2
**Explanation:** Starting with nums = \[1,2,3,4\]:
- Remove numbers 1 and 4, then nums = \[2,3\]
- Remove numbers 2 and 3, then nums = \[\]
There are no more pairs that sum up to 5, hence a total of 2 operations.

**Example 2:**

**Input:** nums = \[3,1,3,4,3\], k = 6
**Output:** 1
**Explanation:** Starting with nums = \[3,1,3,4,3\]:
- Remove the first two 3's, then nums = \[1,4,3\]
There are no more pairs that sum up to 6, hence a total of 1 operation.

**Constraints:**

*   `1 <= nums.length <= 105`
*   `1 <= nums[i] <= 109`
*   `1 <= k <= 109`
Concatenation of Consecutive Binary Numbers

Given an integer `n`, return _the **decimal value** of the binary string formed by concatenating the binary representations of_ `1` _to_ `n` _in order, **modulo**_ `109 + 7`.

**Example 1:**

**Input:** n = 1
**Output:** 1
**Explanation: ** "1 " in binary corresponds to the decimal value 1. 

**Example 2:**

**Input:** n = 3
**Output:** 27
**Explanation:** In binary, 1, 2, and 3 corresponds to  "1 ",  "10 ", and  "11 ".
After concatenating them, we have  "11011 ", which corresponds to the decimal value 27.

**Example 3:**

**Input:** n = 12
**Output:** 505379714
**Explanation**: The concatenation results in  "1101110010111011110001001101010111100 ".
The decimal value of that is 118505380540.
After modulo 109 + 7, the result is 505379714.

**Constraints:**

*   `1 <= n <= 105`
Longest Palindromic Subsequence II

A subsequence of a string `s` is considered a **good palindromic subsequence** if:

*   It is a subsequence of `s`.
*   It is a palindrome (has the same value if reversed).
*   It has an **even** length.
*   No two consecutive characters are equal, except the two middle ones.

For example, if `s = "abcabcabb "`, then `"abba "` is considered a **good palindromic subsequence**, while `"bcb "` (not even length) and `"bbbb "` (has equal consecutive characters) are not.

Given a string `s`, return _the **length** of the **longest good palindromic subsequence** in_ `s`.

**Example 1:**

**Input:** s =  "bbabab "
**Output:** 4
**Explanation:** The longest good palindromic subsequence of s is  "baab ".

**Example 2:**

**Input:** s =  "dcbccacdb "
**Output:** 4
**Explanation:** The longest good palindromic subsequence of s is  "dccd ".

**Constraints:**

*   `1 <= s.length <= 250`
*   `s` consists of lowercase English letters.
Count the Number of Consistent Strings

You are given a string `allowed` consisting of **distinct** characters and an array of strings `words`. A string is **consistent** if all characters in the string appear in the string `allowed`.

Return _the number of **consistent** strings in the array_ `words`.

**Example 1:**

**Input:** allowed =  "ab ", words = \[ "ad ", "bd ", "aaab ", "baa ", "badab "\]
**Output:** 2
**Explanation:** Strings  "aaab " and  "baa " are consistent since they only contain characters 'a' and 'b'.

**Example 2:**

**Input:** allowed =  "abc ", words = \[ "a ", "b ", "c ", "ab ", "ac ", "bc ", "abc "\]
**Output:** 7
**Explanation:** All strings are consistent.

**Example 3:**

**Input:** allowed =  "cad ", words = \[ "cc ", "acd ", "b ", "ba ", "bac ", "bad ", "ac ", "d "\]
**Output:** 4
**Explanation:** Strings  "cc ",  "acd ",  "ac ", and  "d " are consistent.

**Constraints:**

*   `1 <= words.length <= 104`
*   `1 <= allowed.length <= 26`
*   `1 <= words[i].length <= 10`
*   The characters in `allowed` are **distinct**.
*   `words[i]` and `allowed` contain only lowercase English letters.
Sum of Absolute Differences in a Sorted Array

You are given an integer array `nums` sorted in **non-decreasing** order.

Build and return _an integer array_ `result` _with the same length as_ `nums` _such that_ `result[i]` _is equal to the **summation of absolute differences** between_ `nums[i]` _and all the other elements in the array._

In other words, `result[i]` is equal to `sum(|nums[i]-nums[j]|)` where `0 <= j < nums.length` and `j != i` (**0-indexed**).

**Example 1:**

**Input:** nums = \[2,3,5\]
**Output:** \[4,3,5\]
**Explanation:** Assuming the arrays are 0-indexed, then
result\[0\] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
result\[1\] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
result\[2\] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.

**Example 2:**

**Input:** nums = \[1,4,6,8,10\]
**Output:** \[24,15,13,15,21\]

**Constraints:**

*   `2 <= nums.length <= 105`
*   `1 <= nums[i] <= nums[i + 1] <= 104`
Stone Game VI

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

There are `n` stones in a pile. On each player's turn, they can **remove** a stone from the pile and receive points based on the stone's value. Alice and Bob may **value the stones differently**.

You are given two integer arrays of length `n`, `aliceValues` and `bobValues`. Each `aliceValues[i]` and `bobValues[i]` represents how Alice and Bob, respectively, value the `ith` stone.

The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play **optimally**. Both players know the other's values.

Determine the result of the game, and:

*   If Alice wins, return `1`.
*   If Bob wins, return `-1`.
*   If the game results in a draw, return `0`.

**Example 1:**

**Input:** aliceValues = \[1,3\], bobValues = \[2,1\]
**Output:** 1
**Explanation:**
If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.
Bob can only choose stone 0, and will only receive 2 points.
Alice wins.

**Example 2:**

**Input:** aliceValues = \[1,2\], bobValues = \[3,1\]
**Output:** 0
**Explanation:**
If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.
Draw.

**Example 3:**

**Input:** aliceValues = \[2,4,3\], bobValues = \[1,6,7\]
**Output:** -1
**Explanation:**
Regardless of how Alice plays, Bob will be able to have more points than Alice.
For example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.
Bob wins.

**Constraints:**

*   `n == aliceValues.length == bobValues.length`
*   `1 <= n <= 105`
*   `1 <= aliceValues[i], bobValues[i] <= 100`
Delivering Boxes from Storage to Ports

You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a **limit** on the **number of boxes** and the **total weight** that it can carry.

You are given an array `boxes`, where `boxes[i] = [ports​​i​, weighti]`, and three integers `portsCount`, `maxBoxes`, and `maxWeight`.

*   `ports​​i` is the port where you need to deliver the `ith` box and `weightsi` is the weight of the `ith` box.
*   `portsCount` is the number of ports.
*   `maxBoxes` and `maxWeight` are the respective box and weight limits of the ship.

The boxes need to be delivered **in the order they are given**. The ship will follow these steps:

*   The ship will take some number of boxes from the `boxes` queue, not violating the `maxBoxes` and `maxWeight` constraints.
*   For each loaded box **in order**, the ship will make a **trip** to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no **trip** is needed, and the box can immediately be delivered.
*   The ship then makes a return **trip** to storage to take more boxes from the queue.

The ship must end at storage after all the boxes have been delivered.

Return _the **minimum** number of **trips** the ship needs to make to deliver all boxes to their respective ports._

**Example 1:**

**Input:** boxes = \[\[1,1\],\[2,1\],\[1,1\]\], portsCount = 2, maxBoxes = 3, maxWeight = 3
**Output:** 4
**Explanation:** The optimal strategy is as follows: 
- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.
So the total number of trips is 4.
Note that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).

**Example 2:**

**Input:** boxes = \[\[1,2\],\[3,3\],\[3,1\],\[3,1\],\[2,4\]\], portsCount = 3, maxBoxes = 3, maxWeight = 6
**Output:** 6
**Explanation:** The optimal strategy is as follows: 
- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.
- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.
- The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.
So the total number of trips is 2 + 2 + 2 = 6.

**Example 3:**

**Input:** boxes = \[\[1,4\],\[1,2\],\[2,1\],\[2,1\],\[3,2\],\[3,4\]\], portsCount = 3, maxBoxes = 6, maxWeight = 7
**Output:** 6
**Explanation:** The optimal strategy is as follows:
- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.
- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.
- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.
So the total number of trips is 2 + 2 + 2 = 6.

**Constraints:**

*   `1 <= boxes.length <= 105`
*   `1 <= portsCount, maxBoxes, maxWeight <= 105`
*   `1 <= ports​​i <= portsCount`
*   `1 <= weightsi <= maxWeight`
Count of Matches in Tournament

You are given an integer `n`, the number of teams in a tournament that has strange rules:

*   If the current number of teams is **even**, each team gets paired with another team. A total of `n / 2` matches are played, and `n / 2` teams advance to the next round.
*   If the current number of teams is **odd**, one team randomly advances in the tournament, and the rest gets paired. A total of `(n - 1) / 2` matches are played, and `(n - 1) / 2 + 1` teams advance to the next round.

Return _the number of matches played in the tournament until a winner is decided._

**Example 1:**

**Input:** n = 7
**Output:** 6
**Explanation:** Details of the tournament: 
- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
Total number of matches = 3 + 2 + 1 = 6.

**Example 2:**

**Input:** n = 14
**Output:** 13
**Explanation:** Details of the tournament:
- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
Total number of matches = 7 + 3 + 2 + 1 = 13.

**Constraints:**

*   `1 <= n <= 200`
Partitioning Into Minimum Number Of Deci-Binary Numbers

A decimal number is called **deci-binary** if each of its digits is either `0` or `1` without any leading zeros. For example, `101` and `1100` are **deci-binary**, while `112` and `3001` are not.

Given a string `n` that represents a positive decimal integer, return _the **minimum** number of positive **deci-binary** numbers needed so that they sum up to_ `n`_._

**Example 1:**

**Input:** n =  "32 "
**Output:** 3
**Explanation:** 10 + 11 + 11 = 32

**Example 2:**

**Input:** n =  "82734 "
**Output:** 8

**Example 3:**

**Input:** n =  "27346209830709182346 "
**Output:** 9

**Constraints:**

*   `1 <= n.length <= 105`
*   `n` consists of only digits.
*   `n` does not contain any leading zeros and represents a positive integer.
Stone Game VII

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, they can **remove** either the leftmost stone or the rightmost stone from the row and receive points equal to the **sum** of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.

Bob found that he will always lose this game (poor Bob, he always loses), so he decided to **minimize the score's difference**. Alice's goal is to **maximize the difference** in the score.

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

**Example 1:**

**Input:** stones = \[5,3,1,4,2\]
**Output:** 6
**Explanation:** 
- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = \[5,3,1,4\].
- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = \[3,1,4\].
- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = \[1,4\].
- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = \[4\].
- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = \[\].
The score difference is 18 - 12 = 6.

**Example 2:**

**Input:** stones = \[7,90,5,1,100,10,10,2\]
**Output:** 122

**Constraints:**

*   `n == stones.length`
*   `2 <= n <= 1000`
*   `1 <= stones[i] <= 1000`