Skip to content

Commit

Permalink
Find the Winner of the Circular Game Problem No.1823 (saadfareed#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainiftikhar5242 authored Oct 14, 2022
1 parent ce7d25d commit 65a37d9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions C++/Find-the-Winner-of-the-Circular-Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//Name: Hussain Iftikhar
// userName: hussainiftikhar5242
//approach: First store the n values in vector then appy outer loop which will check the first condition and then appply inner for loop to k value which will firstly store the front value in variable and then remove the first value then again push back the value in vector after for loop remove the front value. again for removing the player
class Solution {
public:
int findTheWinner(int n, int k) {
vector<int> player;
for(int i=1;i<=n;i++)
{
player.push_back(i);
}
int value;
while(true)
{
if(player.size() == 1)
{
break;
}
for(int i=1;i<k;i++)
{
value=player.front();
player.erase(player.begin());
player.push_back(value);
}
player.erase(player.begin());
}
return player.front();

}
};

0 comments on commit 65a37d9

Please sign in to comment.