From 9353327289507be976f7f8d3e4cb60ef3e964d2c Mon Sep 17 00:00:00 2001 From: Utkarsh Prakhar <95642114+Utkarsh048@users.noreply.github.com> Date: Mon, 6 Nov 2023 01:28:28 +0530 Subject: [PATCH] Create Find the Winner of an Array Game.py --- Find the Winner of an Array Game.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Find the Winner of an Array Game.py diff --git a/Find the Winner of an Array Game.py b/Find the Winner of an Array Game.py new file mode 100644 index 0000000..d51cfd3 --- /dev/null +++ b/Find the Winner of an Array Game.py @@ -0,0 +1,15 @@ +class Solution: + def getWinner(self, arr: List[int], k: int) -> int: + ans = arr[0] + wins = 0 + + i = 1 + while i < len(arr) and wins < k: + if arr[i] > ans: + ans = arr[i] + wins = 1 + else: + wins += 1 + i += 1 + + return ans