| 1 | class Solution { |
| 2 | public: |
| 3 | int getWinner(vector<int>& arr, int k) { |
| 4 | int count = 0; //taking counter to check how many times a number has won |
| 5 | while(count!=k){ |
| 6 | if(arr[0] > arr[1]){ |
| 7 | arr.push_back(arr[1]); //used to insert the smaller number at the end |
| 8 | arr.erase(arr.begin()+1); //used to remove the smaller number from its orignal position |
| 9 | count++; //increase the number won counter as the same number would have won |
| 10 | } else { |
| 11 | arr.push_back(arr[0]); //used to insert the smaller number at the end |
| 12 | arr.erase(arr.begin()); //used to remove the smaller number from its orignal position |
| 13 | count = 1; //making the won counter to 1 as a new number would have won in this iteration |
| 14 | } |
| 15 | } |
| 16 | return arr[0]; //return the number at the first index, as it is the winner for 'k' times |
| 17 | } |
| 18 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected