Class Solution
java.lang.Object
g0301_0400.s0390_elimination_game.Solution
390 - Elimination Game.<p>Medium</p>
<p>You have a list <code>arr</code> of all integers in the range <code>[1, n]</code> sorted in a strictly increasing order. Apply the following algorithm on <code>arr</code>:</p>
<ul>
<li>Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.</li>
<li>Repeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.</li>
<li>Keep repeating the steps again, alternating left to right and right to left, until a single number remains.</li>
</ul>
<p>Given the integer <code>n</code>, return <em>the last number that remains in</em> <code>arr</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 9</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong></p>
<pre><code> arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr = [2, 4, 6, 8]
arr = [2, 6]
arr = [6]
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 1</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
lastRemaining
public int lastRemaining(int n)
-