> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/weekly-contest/1535.-find-the-winner-of-an-array-game.md).

# 1535. Find the Winner of an Array Game

```
T: O(n)
S: O(1)
```

````java
```java
class Solution {
    public int getWinner(int[] arr, int k) {
        int result = arr[0];
        int winCount = 0;
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > result) {
                result = arr[i];
                winCount = 1;
            } else {
                winCount++;
            }
            if (winCount == k) {
                return result;
            }
        }       
        return result;
    }
}

/***
if before k count, can't find the ans
then after that the winner is still the max in array, so after arr len, return max one in array

T: O(n)
S: O(1)

 */
```
````
