Java☑ 3 Solutions [BruteForce + Using Queue + optimised]
\n\n# Code\n\nclass Solution {\n    // TLE - BruteForce\n    public int getWinner1(int[] arr, int k) {\n        int n = arr.length;\n        int ans = 0;\n     
\n\n# Code\n```\nclass Solution {\n    // TLE - BruteForce\n    public int getWinner1(int[] arr, int k) {\n        int n = arr.length;\n        int ans = 0;\n        int conseq = 0;\n        if(k > n){\n            int max = 0;\n            for(int num : arr) max = Math.max(max, num);\n            return max;\n        }\n\n        while(true){\n            int temp = Math.min(arr[0], arr[1]);\n            arr[0] = Math.max(arr[0], arr[1]);\n            \n            if(ans == 0){\n                ans = arr[0];\n                conseq = 1;\n                if(conseq == k) return ans;\n            }\n            else if(arr[0] == ans){\n                conseq++;\n                if(conseq == k) return ans;\n            }else{\n                ans = arr[0];\n                conseq = 1;\n            }\n            \n            for(int i = 1; i < n - 1; i++){\n                arr[i] = arr[i + 1];\n            }\n            arr[n - 1] = temp;\n        }\n    }\n    // Accepted - Using Queue\n    public int getWinner2(int[] arr, int k) {\n        int n = arr.length;\n        Queue<Integer> queue = new LinkedList<>();\n        for(int i = 2; i < n; i++){\n            queue.offer(arr[i]);\n        }\n\n        int ans = 0;\n        int conseq = 0;\n        if(k > n){\n            int max = 0;\n            for(int num : arr) max = Math.max(max, num);\n            return max;\n        }\n\n         while(true){\n            int temp = Math.min(arr[0], arr[1]);\n            arr[0] = Math.max(arr[0], arr[1]);\n            \n            if(ans == 0){\n                ans = arr[0];\n                conseq = 1;\n                if(conseq == k) return ans;\n            }\n            else if(arr[0] == ans){\n                conseq++;\n                if(conseq == k) return ans;\n            }else{\n                ans = arr[0];\n                conseq = 1;\n            }\n            arr[1] = queue.poll();\n            queue.offer(temp);\n        }\n    }\n\n    // Better - Optimised\n    public int getWinner(int[] arr, int k){\n        int winner = arr[0];\n        int streak = 0;\n\n        int max = 0;\n        for(int num : arr) max = Math.max(max, num);\n        \n        if(k >= arr.length) return max; // rotate - maxElement will come at 0th index atleast once\n\n        for(int i = 1; i < arr.length; i++){\n            if(arr[i] > winner){\n                winner = arr[i];\n                streak = 1;\n            }else{\n                streak++;\n            }\n            // if winner == max stop the game winner is the max \n            if(winner == max || streak == k) return winner;\n        }\n        return -1;\n    }\n}\n```
['Java']