This problem is damnn easy, if you could observe this one simple thing..🕵️
Approach\nLet\'s start by analysing the following e.g.\nInitial Array: [2, 1, 3, 5, 4, 7, 6]\n\nRound 1: Compare 2 and 1, 2 wins, so the array becomes [2, 3, 5,
# Approach\nLet\'s start by analysing the following e.g.\nInitial Array: [2, 1, 3, 5, 4, 7, 6]\n\nRound 1: Compare 2 and 1, 2 wins, so the array becomes [2, 3, 5, 4, 7, 6, 1].\n\nRound 2: Compare 2 and 3, 3 wins, so the array becomes [3, 5, 4, 7, 6, 1, 2].\n\nRound 3: Compare 3 and 5, 5 wins, so the array becomes [5, 4, 7, 6, 1, 2, 3].\n\nRound 4: Compare 5 and 4, 5 wins, so the array becomes [5, 7, 6, 1, 2, 3, 4].\n\nRound 5: Compare 5 and 7, 7 wins, so the array becomes [7, 6, 1, 2, 3, 4, 5].\n\nRound 6: Compare 7 and 6, 7 wins, so the array becomes [7, 1, 2, 3, 4, 5, 6].\n\nIf we do any further comparision 7 which is the max element of the current array, will always win. Thus we can conclude one thing from this observation after the max element is reached how high the value of k is it will always be the winner.\n\nfor all k values before the max element is reached, we can do normal comparision of the curr max element and the next element.\n\ni.e. if curr_max_element>next_element, then we will simply increase its count.\nelse the next_element will become curr_max_element and we can initialise the count value to 1.\n\nThus,\nAny time count==k or curr_max_element=max_element we can simply return curr_max_element.\n\n\n\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int getWinner(int[] arr, int k) {\n        \n    int max=arr[0];\n    for(int i=0;i<arr.length;i++){\n        max=Math.max(max,arr[i]);\n    }\n    int curr_winner=arr[0];\n    int count=0;\n    for(int i=1;i<arr.length;i++){\n    if(curr_winner>arr[i]){\n        count++;\n    }\n    else{\n        curr_winner=arr[i];\n        count=1;\n    }\n    if(count==k || curr_winner==max) return curr_winner;\n    }\n    return 0;\n    }\n}\n```
['Java']