Best Java Solution || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n\n/*\n\n   using HashMap\n\n    \n\n    static int helper(int ar[], int k){\n        ArrayList<Integer> arr = new ArrayList<>();\n        int n = ar.length;\n        for(int i=0; i<n; i++){\n            arr.add(ar[i]);\n        }\n\n        HashMap<Integer,Integer> hp = new HashMap<>();\n\n        while(true){\n            int a = arr.get(0);\n            int b = arr.get(1);\n\n            if(a>b){\n                hp.put(a,hp.getOrDefault(a,0)+1);\n                if(hp.get(a)==k) return a;\n                arr.add(b);\n                arr.remove(1);\n            }else{\n                hp.put(b,hp.getOrDefault(b,0)+1);\n                if(hp.get(b)==k) return b;\n                arr.add(a);\n                arr.remove(0);\n            }\n        }\n        return -1;\n    }\n    */\n\n    static int max(int arr[]){\n        int ans = arr[0];\n        int n = arr.length;\n        for(int i=1; i<n; i++){\n            if(arr[i]>ans) ans = arr[i];\n        }\n        return ans;\n    }\n\n    public int getWinner(int[] arr, int k) {\n        int n = arr.length;\n        if(k>=n) return max(arr);\n\n        int ans = arr[0];\n        int count = 0;\n\n        for(int i=1; i<n; i++){\n            if(ans>arr[i]) count++;\n            else{\n                ans = arr[i];\n                count = 1;\n            }\n\n            if(count==k) return ans;\n        }\n        return ans;\n    }\n}\n```
['Java']