Skip to content
LC-1535 Medium LeetCode

1535. Find the Winner of an Array Game

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 57% Topics: Array, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def getWinner(self, arr, k):
        """
        :type arr: List[int]
        :type k: int
        :rtype: int
        """
        result = arr[0]
        count = 0
        for i in xrange(1, len(arr)):
            if arr[i] > result:
                result = arr[i]
                count = 0
            count += 1
            if (count == k):
                break
        return result

Solution from kamyu104/LeetCode-Solutions · MIT