1535. Find the Winner of an Array Game

T: O(n)
S: O(1)
```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)

 */
```

Last updated