EASIEST SOLUTION U WILL FIND
PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT\n# CONNECT WITH ME\n### https://www.linkedin.com/in/pratay-nandy-9ba57b229/\n#### https://www.instagram.com/pratay_nand
# **PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT**\n# **CONNECT WITH ME**\n### **[https://www.linkedin.com/in/pratay-nandy-9ba57b229/]()**\n#### **[https://www.instagram.com/pratay_nandy/]()**\n\n# Approach\nThe given code defines a C++ class called "Solution" with a public member function "getWinner." The function takes a vector of integers `arr` and an integer `k` as input and returns the winner of a game after k consecutive wins. The game is played as follows:\n\n1. Initially, the `winner` is set to the first element of the `arr` vector.\n2. The `win_cnt` variable is initialized to 0, representing the number of consecutive wins by the current winner.\n3. A loop iterates over the elements of the `arr` vector starting from the second element (index 1).\n4. Inside the loop, it checks whether the current winner is greater than the current element of the array (arr[i]).\n   - If the current winner is greater, it means the current element lost the game, so `win_cnt` is incremented by 1.\n   - If the current element is greater, it becomes the new winner, and `win_cnt` is set to 1, indicating one consecutive win.\n5. It checks whether `win_cnt` has reached the value of `k`. If it has, it returns the current winner as the winner of the game.\n6. If the loop completes without finding a winner after `k` consecutive wins, it returns the current `winner`.\n\nThe overall approach of this code is to simulate a game where two players compete, and the winner is determined based on consecutive wins. The loop keeps track of the consecutive wins and updates the winner accordingly. When the required number of consecutive wins (`k`) is achieved, the function returns the winner. If no winner is found after processing the entire array, it returns the current winner.\n\nThis code assumes that there will always be a winner before reaching the end of the array because it doesn\'t handle cases where there may not be `k` consecutive wins.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:0(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![upvote2.png](https://assets.leetcode.com/users/images/8e8c4408-d509-4f8c-8e0e-d386c1203428_1699205377.0120504.png)\n\n# Code\n```\nclass Solution {\npublic:\n    int getWinner(vector<int>& arr, int k) {\n        int winner = arr[0];\n        int win_cnt=0;\n        for(int i = 1 ; i < arr.size(); i++ )\n        {\n            if(winner > arr[i])\n            {\n                win_cnt++;\n            }\n            else\n            {\n                winner = arr[i];\n                win_cnt = 1;;\n            }\n            if(win_cnt == k )\n            {\n                return winner;\n            }\n        }\n        return winner;  \n    }\n}; \n```
['Array', 'Simulation', 'C++']