Package g1601_1700.s1686_stone_game_vi
Class Solution
java.lang.Object
g1601_1700.s1686_stone_game_vi.Solution
1686 - Stone Game VI.<p>Medium</p>
<p>Alice and Bob take turns playing a game, with Alice starting first.</p>
<p>There are <code>n</code> stones in a pile. On each player’s turn, they can <strong>remove</strong> a stone from the pile and receive points based on the stone’s value. Alice and Bob may <strong>value the stones differently</strong>.</p>
<p>You are given two integer arrays of length <code>n</code>, <code>aliceValues</code> and <code>bobValues</code>. Each <code>aliceValues[i]</code> and <code>bobValues[i]</code> represents how Alice and Bob, respectively, value the <code>i<sup>th</sup></code> stone.</p>
<p>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 <strong>optimally</strong>. Both players know the other’s values.</p>
<p>Determine the result of the game, and:</p>
<ul>
<li>If Alice wins, return <code>1</code>.</li>
<li>If Bob wins, return <code>-1</code>.</li>
<li>If the game results in a draw, return <code>0</code>.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> aliceValues = [1,3], bobValues = [2,1]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.</p>
<p>Bob can only choose stone 0, and will only receive 2 points.</p>
<p>Alice wins.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> aliceValues = [1,2], bobValues = [3,1]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.</p>
<p>Draw.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> aliceValues = [2,4,3], bobValues = [1,6,7]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> Regardless of how Alice plays, Bob will be able to have more points than Alice.</p>
<p>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.</p>
<p>Bob wins.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == aliceValues.length == bobValues.length</code></li>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>1 <= aliceValues[i], bobValues[i] <= 100</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
stoneGameVI
public int stoneGameVI(int[] aliceValues, int[] bobValues)
-