bowang0911/leetcode huggingface dataset:
Find the Student that Will Replace the Chalk

There are `n` students in a class numbered from `0` to `n - 1`. The teacher will give each student a problem starting with the student number `0`, then the student number `1`, and so on until the teacher reaches the student number `n - 1`. After that, the teacher will restart the process, starting with the student number `0` again.

You are given a **0-indexed** integer array `chalk` and an integer `k`. There are initially `k` pieces of chalk. When the student number `i` is given a problem to solve, they will use `chalk[i]` pieces of chalk to solve that problem. However, if the current number of chalk pieces is **strictly less** than `chalk[i]`, then the student number `i` will be asked to **replace** the chalk.

Return _the **index** of the student that will **replace** the chalk pieces_.

**Example 1:**

**Input:** chalk = \[5,1,5\], k = 22
**Output:** 0
**Explanation:** The students go in turns as follows:
- Student number 0 uses 5 chalk, so k = 17.
- Student number 1 uses 1 chalk, so k = 16.
- Student number 2 uses 5 chalk, so k = 11.
- Student number 0 uses 5 chalk, so k = 6.
- Student number 1 uses 1 chalk, so k = 5.
- Student number 2 uses 5 chalk, so k = 0.
Student number 0 does not have enough chalk, so they will have to replace it.

**Example 2:**

**Input:** chalk = \[3,4,1,2\], k = 25
**Output:** 1
**Explanation:** The students go in turns as follows:
- Student number 0 uses 3 chalk so k = 22.
- Student number 1 uses 4 chalk so k = 18.
- Student number 2 uses 1 chalk so k = 17.
- Student number 3 uses 2 chalk so k = 15.
- Student number 0 uses 3 chalk so k = 12.
- Student number 1 uses 4 chalk so k = 8.
- Student number 2 uses 1 chalk so k = 7.
- Student number 3 uses 2 chalk so k = 5.
- Student number 0 uses 3 chalk so k = 2.
Student number 1 does not have enough chalk, so they will have to replace it.

**Constraints:**

*   `chalk.length == n`
*   `1 <= n <= 105`
*   `1 <= chalk[i] <= 105`
*   `1 <= k <= 109`
Largest Magic Square

A `k x k` **magic square** is a `k x k` grid filled with integers such that every row sum, every column sum, and both diagonal sums are **all equal**. The integers in the magic square **do not have to be distinct**. Every `1 x 1` grid is trivially a **magic square**.

Given an `m x n` integer `grid`, return _the **size** (i.e., the side length_ `k`_) of the **largest magic square** that can be found within this grid_.

**Example 1:**

**Input:** grid = \[\[7,1,4,5,6\],\[2,5,1,6,4\],\[1,5,4,3,2\],\[1,2,7,3,4\]\]
**Output:** 3
**Explanation:** The largest magic square has a size of 3.
Every row sum, column sum, and diagonal sum of this magic square is equal to 12.
- Row sums: 5+1+6 = 5+4+3 = 2+7+3 = 12
- Column sums: 5+5+2 = 1+4+7 = 6+3+3 = 12
- Diagonal sums: 5+4+3 = 6+4+2 = 12

**Example 2:**

**Input:** grid = \[\[5,1,3,1\],\[9,3,3,1\],\[1,3,3,8\]\]
**Output:** 2

**Constraints:**

*   `m == grid.length`
*   `n == grid[i].length`
*   `1 <= m, n <= 50`
*   `1 <= grid[i][j] <= 106`
Minimum Cost to Change the Final Value of Expression

You are given a **valid** boolean expression as a string `expression` consisting of the characters `'1'`,`'0'`,`'&'` (bitwise **AND** operator),`'|'` (bitwise **OR** operator),`'('`, and `')'`.

*   For example, `"()1|1 "` and `"(1)&() "` are **not valid** while `"1 "`, `"(((1))|(0)) "`, and `"1|(0&(1)) "` are **valid** expressions.

Return _the **minimum cost** to change the final value of the expression_.

*   For example, if `expression = "1|1|(0&0)&1 "`, its **value** is `1|1|(0&0)&1 = 1|1|0&1 = 1|0&1 = 1&1 = 1`. We want to apply operations so that the **new** expression evaluates to `0`.

The **cost** of changing the final value of an expression is the **number of operations** performed on the expression. The types of **operations** are described as follows:

*   Turn a `'1'` into a `'0'`.
*   Turn a `'0'` into a `'1'`.
*   Turn a `'&'` into a `'|'`.
*   Turn a `'|'` into a `'&'`.

**Note:** `'&'` does **not** take precedence over `'|'` in the **order of calculation**. Evaluate parentheses **first**, then in **left-to-right** order.

**Example 1:**

**Input:** expression =  "1&(0|1) "
**Output:** 1
**Explanation:** We can turn  "1&(0**|**1) " into  "1&(0**&**1) " by changing the '|' to a '&' using 1 operation.
The new expression evaluates to 0. 

**Example 2:**

**Input:** expression =  "(0&0)&(0&0&0) "
**Output:** 3
**Explanation:** We can turn  "(0**&0**)**&**(0&0&0) " into  "(0**|1**)**|**(0&0&0) " using 3 operations.
The new expression evaluates to 1.

**Example 3:**

**Input:** expression =  "(0|(1|0&1)) "
**Output:** 1
**Explanation:** We can turn  "(0|(**1**|0&1)) " into  "(0|(**0**|0&1)) " using 1 operation.
The new expression evaluates to 0.

**Constraints:**

*   `1 <= expression.length <= 105`
*   `expression` only contains `'1'`,`'0'`,`'&'`,`'|'`,`'('`, and `')'`
*   All parentheses are properly matched.
*   There will be no empty parentheses (i.e: `"() "` is not a substring of `expression`).
Redistribute Characters to Make All Strings Equal

You are given an array of strings `words` (**0-indexed**).

In one operation, pick two **distinct** indices `i` and `j`, where `words[i]` is a non-empty string, and move **any** character from `words[i]` to **any** position in `words[j]`.

Return `true` _if you can make **every** string in_ `words` _**equal** using **any** number of operations_, _and_ `false` _otherwise_.

**Example 1:**

**Input:** words = \[ "abc ", "aabc ", "bc "\]
**Output:** true
**Explanation:** Move the first 'a' in `words[1] to the front of words[2], to make` `words[1]` =  "abc " and words\[2\] =  "abc ".
All the strings are now equal to  "abc ", so return `true`.

**Example 2:**

**Input:** words = \[ "ab ", "a "\]
**Output:** false
**Explanation:** It is impossible to make all the strings equal using the operation.

**Constraints:**

*   `1 <= words.length <= 100`
*   `1 <= words[i].length <= 100`
*   `words[i]` consists of lowercase English letters.
Maximum Number of Removable Characters

You are given two strings `s` and `p` where `p` is a **subsequence** of `s`. You are also given a **distinct 0-indexed** integer array `removable` containing a subset of indices of `s` (`s` is also **0-indexed**).

You want to choose an integer `k` (`0 <= k <= removable.length`) such that, after removing `k` characters from `s` using the **first** `k` indices in `removable`, `p` is still a **subsequence** of `s`. More formally, you will mark the character at `s[removable[i]]` for each `0 <= i < k`, then remove all marked characters and check if `p` is still a subsequence.

Return _the **maximum**_ `k` _you can choose such that_ `p` _is still a **subsequence** of_ `s` _after the removals_.

A **subsequence** of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

**Example 1:**

**Input:** s =  "abcacb ", p =  "ab ", removable = \[3,1,0\]
**Output:** 2
**Explanation**: After removing the characters at indices 3 and 1,  "a**b**c**a**cb " becomes  "accb ".
 "ab " is a subsequence of  "**a**cc**b** ".
If we remove the characters at indices 3, 1, and 0,  "**ab**c**a**cb " becomes  "ccb ", and  "ab " is no longer a subsequence.
Hence, the maximum k is 2.

**Example 2:**

**Input:** s =  "abcbddddd ", p =  "abcd ", removable = \[3,2,1,4,5,6\]
**Output:** 1
**Explanation**: After removing the character at index 3,  "abc**b**ddddd " becomes  "abcddddd ".
 "abcd " is a subsequence of  "**abcd**dddd ".

**Example 3:**

**Input:** s =  "abcab ", p =  "abc ", removable = \[0,1,2,3,4\]
**Output:** 0
**Explanation**: If you remove the first index in the array removable,  "abc " is no longer a subsequence.

**Constraints:**

*   `1 <= p.length <= s.length <= 105`
*   `0 <= removable.length < s.length`
*   `0 <= removable[i] < s.length`
*   `p` is a **subsequence** of `s`.
*   `s` and `p` both consist of lowercase English letters.
*   The elements in `removable` are **distinct**.
Merge Triplets to Form Target Triplet

A **triplet** is an array of three integers. You are given a 2D integer array `triplets`, where `triplets[i] = [ai, bi, ci]` describes the `ith` **triplet**. You are also given an integer array `target = [x, y, z]` that describes the **triplet** you want to obtain.

To obtain `target`, you may apply the following operation on `triplets` **any number** of times (possibly **zero**):

*   Choose two indices (**0-indexed**) `i` and `j` (`i != j`) and **update** `triplets[j]` to become `[max(ai, aj), max(bi, bj), max(ci, cj)]`.
    *   For example, if `triplets[i] = [2, 5, 3]` and `triplets[j] = [1, 7, 5]`, `triplets[j]` will be updated to `[max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5]`.

Return `true` _if it is possible to obtain the_ `target` _**triplet**_ `[x, y, z]` _as an **element** of_ `triplets`_, or_ `false` _otherwise_.

**Example 1:**

**Input:** triplets = \[\[2,5,3\],\[1,8,4\],\[1,7,5\]\], target = \[2,7,5\]
**Output:** true
**Explanation:** Perform the following operations:
- Choose the first and last triplets \[\[2,5,3\],\[1,8,4\],\[1,7,5\]\]. Update the last triplet to be \[max(2,1), max(5,7), max(3,5)\] = \[2,7,5\]. triplets = \[\[2,5,3\],\[1,8,4\],\[2,7,5\]\]
The target triplet \[2,7,5\] is now an element of triplets.

**Example 2:**

**Input:** triplets = \[\[3,4,5\],\[4,5,6\]\], target = \[3,2,5\]
**Output:** false
**Explanation:** It is impossible to have \[3,2,5\] as an element because there is no 2 in any of the triplets.

**Example 3:**

**Input:** triplets = \[\[2,5,3\],\[2,3,4\],\[1,2,5\],\[5,2,3\]\], target = \[5,5,5\]
**Output:** true
**Explanation:** Perform the following operations:
- Choose the first and third triplets \[\[2,5,3\],\[2,3,4\],\[1,2,5\],\[5,2,3\]\]. Update the third triplet to be \[max(2,1), max(5,2), max(3,5)\] = \[2,5,5\]. triplets = \[\[2,5,3\],\[2,3,4\],\[2,5,5\],\[5,2,3\]\].
- Choose the third and fourth triplets \[\[2,5,3\],\[2,3,4\],\[2,5,5\],\[5,2,3\]\]. Update the fourth triplet to be \[max(2,5), max(5,2), max(5,3)\] = \[5,5,5\]. triplets = \[\[2,5,3\],\[2,3,4\],\[2,5,5\],\[5,5,5\]\].
The target triplet \[5,5,5\] is now an element of triplets.

**Constraints:**

*   `1 <= triplets.length <= 105`
*   `triplets[i].length == target.length == 3`
*   `1 <= ai, bi, ci, x, y, z <= 1000`
The Earliest and Latest Rounds Where Players Compete

There is a tournament where `n` players are participating. The players are standing in a single row and are numbered from `1` to `n` based on their **initial** standing position (player `1` is the first player in the row, player `2` is the second player in the row, etc.).

The tournament consists of multiple rounds (starting from round number `1`). In each round, the `ith` player from the front of the row competes against the `ith` player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.

*   For example, if the row consists of players `1, 2, 4, 6, 7`
    *   Player `1` competes against player `7`.
    *   Player `2` competes against player `6`.
    *   Player `4` automatically advances to the next round.

After each round is over, the winners are lined back up in the row based on the **original ordering** assigned to them initially (ascending order).

The players numbered `firstPlayer` and `secondPlayer` are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may **choose** the outcome of this round.

Given the integers `n`, `firstPlayer`, and `secondPlayer`, return _an integer array containing two values, the **earliest** possible round number and the **latest** possible round number in which these two players will compete against each other, respectively_.

**Example 1:**

**Input:** n = 11, firstPlayer = 2, secondPlayer = 4
**Output:** \[3,4\]
**Explanation:**
One possible scenario which leads to the earliest round number:
First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Second round: 2, 3, 4, 5, 6, 11
Third round: 2, 3, 4
One possible scenario which leads to the latest round number:
First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Second round: 1, 2, 3, 4, 5, 6
Third round: 1, 2, 4
Fourth round: 2, 4

**Example 2:**

**Input:** n = 5, firstPlayer = 1, secondPlayer = 5
**Output:** \[1,1\]
**Explanation:** The players numbered 1 and 5 compete in the first round.
There is no way to make them compete in any other round.

**Constraints:**

*   `2 <= n <= 28`
*   `1 <= firstPlayer < secondPlayer <= n`
Find a Peak Element II

A **peak** element in a 2D grid is an element that is **strictly greater** than all of its **adjacent** neighbors to the left, right, top, and bottom.

Given a **0-indexed** `m x n` matrix `mat` where **no two adjacent cells are equal**, find **any** peak element `mat[i][j]` and return _the length 2 array_ `[i,j]`.

You may assume that the entire matrix is surrounded by an **outer perimeter** with the value `-1` in each cell.

You must write an algorithm that runs in `O(m log(n))` or `O(n log(m))` time.

**Example 1:**

**Input:** mat = \[\[1,4\],\[3,2\]\]
**Output:** \[0,1\]
**Explanation:** Both 3 and 4 are peak elements so \[1,0\] and \[0,1\] are both acceptable answers.

**Example 2:**

**Input:** mat = \[\[10,20,15\],\[21,30,14\],\[7,16,32\]\]
**Output:** \[1,1\]
**Explanation:** Both 30 and 32 are peak elements so \[1,1\] and \[2,2\] are both acceptable answers.

**Constraints:**

*   `m == mat.length`
*   `n == mat[i].length`
*   `1 <= m, n <= 500`
*   `1 <= mat[i][j] <= 105`
*   No two adjacent cells are equal.
Depth of BST Given Insertion Order

You are given a **0-indexed** integer array `order` of length `n`, a **permutation** of integers from `1` to `n` representing the **order** of insertion into a **binary search tree**.

A binary search tree is defined as follows:

*   The left subtree of a node contains only nodes with keys **less than** the node's key.
*   The right subtree of a node contains only nodes with keys **greater than** the node's key.
*   Both the left and right subtrees must also be binary search trees.

The binary search tree is constructed as follows:

*   `order[0]` will be the **root** of the binary search tree.
*   All subsequent elements are inserted as the **child** of **any** existing node such that the binary search tree properties hold.

Return _the **depth** of the binary search tree_.

A binary tree's **depth** is the number of **nodes** along the **longest path** from the root node down to the farthest leaf node.

**Example 1:**

**Input:** order = \[2,1,4,3\]
**Output:** 3
**Explanation:** The binary search tree has a depth of 3 with path 2->3->4.

**Example 2:**

**Input:** order = \[2,1,3,4\]
**Output:** 3
**Explanation:** The binary search tree has a depth of 3 with path 2->3->4.

**Example 3:**

**Input:** order = \[1,2,3,4\]
**Output:** 4
**Explanation:** The binary search tree has a depth of 4 with path 1->2->3->4.

**Constraints:**

*   `n == order.length`
*   `1 <= n <= 105`
*   `order` is a permutation of integers between `1` and `n`.
Largest Odd Number in String

You are given a string `num`, representing a large integer. Return _the **largest-valued odd** integer (as a string) that is a **non-empty substring** of_ `num`_, or an empty string_ `" "` _if no odd integer exists_.

A **substring** is a contiguous sequence of characters within a string.

**Example 1:**

**Input:** num =  "52 "
**Output:**  "5 "
**Explanation:** The only non-empty substrings are  "5 ",  "2 ", and  "52 ".  "5 " is the only odd number.

**Example 2:**

**Input:** num =  "4206 "
**Output:**  " "
**Explanation:** There are no odd numbers in  "4206 ".

**Example 3:**

**Input:** num =  "35427 "
**Output:**  "35427 "
**Explanation:**  "35427 " is already an odd number.

**Constraints:**

*   `1 <= num.length <= 105`
*   `num` only consists of digits and does not contain any leading zeros.
The Number of Full Rounds You Have Played

You are participating in an online chess tournament. There is a chess round that starts every `15` minutes. The first round of the day starts at `00:00`, and after every `15` minutes, a new round starts.

*   For example, the second round starts at `00:15`, the fourth round starts at `00:45`, and the seventh round starts at `01:30`.

You are given two strings `loginTime` and `logoutTime` where:

*   `loginTime` is the time you will login to the game, and
*   `logoutTime` is the time you will logout from the game.

If `logoutTime` is **earlier** than `loginTime`, this means you have played from `loginTime` to midnight and from midnight to `logoutTime`.

Return _the number of full chess rounds you have played in the tournament_.

**Note:** All the given times follow the 24-hour clock. That means the first round of the day starts at `00:00` and the last round of the day starts at `23:45`.

**Example 1:**

**Input:** loginTime =  "09:31 ", logoutTime =  "10:14 "
**Output:** 1
**Explanation:** You played one full round from 09:45 to 10:00.
You did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.
You did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.

**Example 2:**

**Input:** loginTime =  "21:30 ", logoutTime =  "03:00 "
**Output:** 22
**Explanation:** You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.
10 + 12 = 22.

**Constraints:**

*   `loginTime` and `logoutTime` are in the format `hh:mm`.
*   `00 <= hh <= 23`
*   `00 <= mm <= 59`
*   `loginTime` and `logoutTime` are not equal.
Count Sub Islands

You are given two `m x n` binary matrices `grid1` and `grid2` containing only `0`'s (representing water) and `1`'s (representing land). An **island** is a group of `1`'s connected **4-directionally** (horizontal or vertical). Any cells outside of the grid are considered water cells.

An island in `grid2` is considered a **sub-island** if there is an island in `grid1` that contains **all** the cells that make up **this** island in `grid2`.

Return the _**number** of islands in_ `grid2` _that are considered **sub-islands**_.

**Example 1:**

**Input:** grid1 = \[\[1,1,1,0,0\],\[0,1,1,1,1\],\[0,0,0,0,0\],\[1,0,0,0,0\],\[1,1,0,1,1\]\], grid2 = \[\[1,1,1,0,0\],\[0,0,1,1,1\],\[0,1,0,0,0\],\[1,0,1,1,0\],\[0,1,0,1,0\]\]
**Output:** 3
**Explanation:** In the picture above, the grid on the left is grid1 and the grid on the right is grid2.
The 1s colored red in grid2 are those considered to be part of a sub-island. There are three sub-islands.

**Example 2:**

**Input:** grid1 = \[\[1,0,1,0,1\],\[1,1,1,1,1\],\[0,0,0,0,0\],\[1,1,1,1,1\],\[1,0,1,0,1\]\], grid2 = \[\[0,0,0,0,0\],\[1,1,1,1,1\],\[0,1,0,1,0\],\[0,1,0,1,0\],\[1,0,0,0,1\]\]
**Output:** 2 
**Explanation:** In the picture above, the grid on the left is grid1 and the grid on the right is grid2.
The 1s colored red in grid2 are those considered to be part of a sub-island. There are two sub-islands.

**Constraints:**

*   `m == grid1.length == grid2.length`
*   `n == grid1[i].length == grid2[i].length`
*   `1 <= m, n <= 500`
*   `grid1[i][j]` and `grid2[i][j]` are either `0` or `1`.
Minimum Absolute Difference Queries

The **minimum absolute difference** of an array `a` is defined as the **minimum value** of `|a[i] - a[j]|`, where `0 <= i < j < a.length` and `a[i] != a[j]`. If all elements of `a` are the **same**, the minimum absolute difference is `-1`.

*   For example, the minimum absolute difference of the array `[5,2,3,7,2]` is `|2 - 3| = 1`. Note that it is not `0` because `a[i]` and `a[j]` must be different.

You are given an integer array `nums` and the array `queries` where `queries[i] = [li, ri]`. For each query `i`, compute the **minimum absolute difference** of the **subarray** `nums[li...ri]` containing the elements of `nums` between the **0-based** indices `li` and `ri` (**inclusive**).

Return _an **array**_ `ans` _where_ `ans[i]` _is the answer to the_ `ith` _query_.

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

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

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

**Example 1:**

**Input:** nums = \[1,3,4,8\], queries = \[\[0,1\],\[1,2\],\[2,3\],\[0,3\]\]
**Output:** \[2,1,4,1\]
**Explanation:** The queries are processed as follows:
- queries\[0\] = \[0,1\]: The subarray is \[1,3\] and the minimum absolute difference is |1-3| = 2.
- queries\[1\] = \[1,2\]: The subarray is \[3,4\] and the minimum absolute difference is |3-4| = 1.
- queries\[2\] = \[2,3\]: The subarray is \[4,8\] and the minimum absolute difference is |4-8| = 4.
- queries\[3\] = \[0,3\]: The subarray is \[1,3,4,8\] and the minimum absolute difference is |3-4| = 1.

**Example 2:**

**Input:** nums = \[4,5,2,2,7,10\], queries = \[\[2,3\],\[0,2\],\[0,5\],\[3,5\]\]
**Output:** \[-1,1,1,3\]
**Explanation:** The queries are processed as follows:
- queries\[0\] = \[2,3\]: The subarray is \[2,2\] and the minimum absolute difference is -1 because all the
  elements are the same.
- queries\[1\] = \[0,2\]: The subarray is \[4,5,2\] and the minimum absolute difference is |4-5| = 1.
- queries\[2\] = \[0,5\]: The subarray is \[4,5,2,2,7,10\] and the minimum absolute difference is |4-5| = 1.
- queries\[3\] = \[3,5\]: The subarray is \[2,7,10\] and the minimum absolute difference is |7-10| = 3.

**Constraints:**

*   `2 <= nums.length <= 105`
*   `1 <= nums[i] <= 100`
*   `1 <= queries.length <= 2 * 104`
*   `0 <= li < ri < nums.length`
Game of Nim

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

In this game, there are `n` piles of stones. On each player's turn, the player should remove any **positive** number of stones from a non-empty pile **of his or her choice**. The first player who cannot make a move loses, and the other player wins.

Given an integer array `piles`, where `piles[i]` is the number of stones in the `ith` pile, return `true` _if Alice wins, or_ `false` _if Bob wins_.

Both Alice and Bob play **optimally**.

**Example 1:**

**Input:** piles = \[1\]
**Output:** true
**Explanation:** There is only one possible scenario:
- On the first turn, Alice removes one stone from the first pile. piles = \[0\].
- On the second turn, there are no stones left for Bob to remove. Alice wins.

**Example 2:**

**Input:** piles = \[1,1\]
**Output:** false
**Explanation:** It can be proven that Bob will always win. One possible scenario is:
- On the first turn, Alice removes one stone from the first pile. piles = \[0,1\].
- On the second turn, Bob removes one stone from the second pile. piles = \[0,0\].
- On the third turn, there are no stones left for Alice to remove. Bob wins.

**Example 3:**

**Input:** piles = \[1,2,3\]
**Output:** false
**Explanation:** It can be proven that Bob will always win. One possible scenario is:
- On the first turn, Alice removes three stones from the third pile. piles = \[1,2,0\].
- On the second turn, Bob removes one stone from the second pile. piles = \[1,1,0\].
- On the third turn, Alice removes one stone from the first pile. piles = \[0,1,0\].
- On the fourth turn, Bob removes one stone from the second pile. piles = \[0,0,0\].
- On the fifth turn, there are no stones left for Alice to remove. Bob wins.

**Constraints:**

*   `n == piles.length`
*   `1 <= n <= 7`
*   `1 <= piles[i] <= 7`

**Follow-up:** Could you find a linear time solution? Although the linear time solution may be beyond the scope of an interview, it could be interesting to know.