Most Unique C++ solution || Simple approach || O(N) Time complexity
We simply need to check if we have an element which is maximum among the next k elements including itself. Else, the maximum of the array will be the answer.\nL
We simply need to check if we have an element which is maximum among the next k elements including itself. Else, the maximum of the array will be the answer.\nLets see in example 1, where when 5 is maximum for itself and the next element so k=2 then it is the answer. If we reach the maximum element of the total array the it is the answer because no matter how many times we repeat the process, it will always be the maximum. \n\n# Code\n```\nclass Solution {\npublic:\n    int getWinner(vector<int>& arr, int k) {\n        int win = 0, winner = *max_element(arr.begin(), arr.end()), mx = arr[0]; \n        if(winner == arr[0] || k > arr.size())    return winner; // If the first element is maximum or k is greater than size of array then return maximum.\n// This is because if k>arr.size() then we will reach the maximum element somwhow and then it will always be the maximum for all comparisons\n        for(int i=1; i<arr.size(); i++)\n        {\n            if(arr[i]==winner)    break; // If we reach the maximum then break because it will always be the maximum\n            if(arr[i] > mx){\n                mx = arr[i];\n                win = 0;\n            }\n            if(++win == k)  return mx; //If win_count=k then return the current max number\n        }\n        return winner;\n    }\n};\n```
['C++']