<p>Given an integer array <code>arr</code> of <strong>distinct</strong> integers and an integer <code>k</code>.</p>

<p>A game will be played between the first two elements of the array (i.e. <code>arr[0]</code> and <code>arr[1]</code>). In each round of the game, we compare <code>arr[0]</code> with <code>arr[1]</code>, the larger integer wins and remains at position <code>0</code>, and the smaller integer moves to the end of the array. The game ends when an integer wins <code>k</code> consecutive rounds.</p>

<p>Return <em>the integer which will win the game</em>.</p>

<p>It is <strong>guaranteed</strong> that there will be a winner of the game.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [2,1,3,5,4,6,7], k = 2
<strong>Output:</strong> 5
<strong>Explanation:</strong> Let&#39;s see the rounds of the game:
Round |       arr       | winner | win_count
  1   | [2,1,3,5,4,6,7] | 2      | 1
  2   | [2,3,5,4,6,7,1] | 3      | 1
  3   | [3,5,4,6,7,1,2] | 5      | 1
  4   | [5,4,6,7,1,2,3] | 5      | 2
So we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr = [3,2,1], k = 10
<strong>Output:</strong> 3
<strong>Explanation:</strong> 3 will win the first 10 rounds consecutively.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= arr[i] &lt;= 10<sup>6</sup></code></li>
	<li><code>arr</code> contains <strong>distinct</strong> integers.</li>
	<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>

# class Solution:
#     def getWinner(self, arr: List[int], k: int) -> int:
#         count1 = 0
#         count2 = 0
        
#         for i in range(0, len(arr) - 1):
#             if count1 == k or count2 == k:
#                 return arr[0]

#             if arr[0] > arr[1]:
#                 arr.append(arr[1])
#                 arr.remove(arr[1])
#                 count1 += 1
#                 count2 = 0
#             else:
#                 arr.append(arr[0])
#                 arr.remove(arr[0])
#                 count2 += 1
#                 count1 = 0
        
#         return arr[0]

class Solution:
    def getWinner(self, arr: List[int], k: int) -> int:
        count = 0  # Keep track of the number of consecutive wins
        current_winner = arr[0]  # Assume the first element is the current winner
        
        for i in range(1, len(arr)):
            if arr[i] > current_winner:
                current_winner = arr[i]  # Update the current winner
                count = 1  # Reset count since the winner changed
            else:
                count += 1  # Increment count if the current winner wins again

            # If the current winner wins k consecutive times or we run out of elements
            if count == k:
                return current_winner

        return current_winner  # If no one wins k consecutive times, return the largest element


30400