Queue Solution (with step by step explanation)
Intuition\nwe will use Queue to solve this problem\n# Approach\nfirst set two varibles max and win first to store maximum value of array, second to count winstr
# Intuition\nwe will use Queue to solve this problem\n# Approach\nfirst set two varibles max and win first to store maximum value of array, second to count winstreak. declare queue and iterate over array on each iteration check max value with current array element to find max and add each element to queue. Check if k more or equals to array length if true return max, if false then take first element from queue and start iterate until queue is not empty, on each iteration take next element from queue and compare them if a more than b then we add b to queue and increment winstreak, else we add a to queue and set a to b and drop winstreak to 1. If we have winstreak equals k or a equals max value of arraay, return a.\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(n)\n# Code\n```\nclass Solution {\n    public int getWinner(int[] arr, int k) {\n        // declare max to store maximum value of array\n        int max = 0;\n        // declare win to store winstreak\n        int win = 0;\n        // declare queue to simulate game\n        Queue<Integer> que = new LinkedList();\n        // iterate over array\n        for(int i = 0; i < arr.length; i++) {\n            // set max value on each iteration\n            max = Math.max(max, arr[i]);\n            // add each element to queue\n            que.add(arr[i]);\n        }\n        // check if k more or equals to array length, if true return max value\n        if(k >= arr.length) return max;\n        // get first element from queue\n        int a = que.remove();\n        // start simulation:\n        while(que.size() > 0) {\n            // get second element from queue\n            int b = que.remove();\n            // if a more than b\n            if(a > b) {\n                // add b to queue\n                que.add(b);\n                // increase winstreak\n                win++;\n            // else\n            } else {\n                // add a to queue\n                que.add(a);\n                // set a equals to b\n                a = b;\n                // drop winstreak\n                win = 1;\n            }\n            // if win equals k or a equals max return a\n            if(win == k || a == max) return a;\n        }\n        // return max value\n        return max;\n    }\n}\n```
['Array', 'Linked List', 'Queue', 'Java']