id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int>& nums,int i,int j,vector<vector<int>>& dp){\n if(i>j){\n return 0;\n }\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n int take_i=nums[i]+min(solve(nums,i+2,j,dp),solve(nums,i+1,j-1,dp));\n int take_j=nums[j]+min(so...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
2
{ "code": "class Solution {\npublic:\n int dfs(int i,int j,vector<int>& nums,int turn,vector<vector<int>> &dp){\n if(i>j) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int ans=0;\n\n if(turn==0) ans=max(nums[i]+dfs(i+1,j,nums,1,dp),nums[j]+dfs(i,j-1,nums,1,dp));\n else\n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
2
{ "code": "class Solution {\npublic:\n bool predictTheWinner(vector<int>& nums) {\n int n=nums.size();\n \n vector<vector<int>> dp(n,vector<int>(n,0));\n for(int i=0;i<n;i++){\n dp[i][i]=nums[i];\n }\n for(int i=n-2;i>=0;i--){\n for(int j=i+1;j<n;j++){...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
2
{ "code": "class Solution {\npublic:\n bool predictTheWinner(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> dp(n, vector<int>(n, 0));\n \n for (int i = 0; i < n; i++) {\n dp[i][i] = nums[i];\n }\n \n for (int len = 2; len <= n; len++) {...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n\n int memFunc(vector<int>& nums, vector<vector<int>> &dp, int s, int e){\n if(s > e){\n return 0; \n }\n\n if(dp[s][e] != -1) return dp[s][e] ; \n\n dp[s][e] = max(nums[s] - memFunc(nums, dp, s+1, e), nums[e] - memFunc(nums, dp, s, e-1))...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "// Recursion tarika 1\nclass Solution1 {\npublic:\n // Ye function player1 ka score nikalega, min-max game strategy leke,\n\n long long solve(vector<int>& nums, int i, int j, vector<vector<long long>>& mem) {\n if (i > j) return 0;\n\n // 1 ne i liya, phir 2 agar i+1 lega to solve(i+2, ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n/*OPTIMAL GAME STRATEGY CONCEPT:\nwhen its your turn do your best \nwhen its others turn expect least from him */\n\n// RECURSION 2 : storing the difference of p1 and whatever the p2 returns and if this difference is >=0 p1 wins\n#define ll long long int\n/*ll f(int s,int e,vect...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n\n bool fun(vector<int>& nums,int o,int sa,int sb,int i,int j,int n,vector<vector<vector<int>>>&dp,int sum){\n if( i>=n || j<0)return sa>=sb;\n \n if(sa>=sum)return true;\n if(i>j){\n if(sa>=sb)return true;\n else return false;...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n\n using pii = pair<int, int>;\n bool predictTheWinner(vector<int>& nums) {\n int n = nums.size();\n vector<vector<pii>> p1(n + 1, vector<pii>(n + 1, make_pair(0, 0)));\n vector<vector<pii>> p2(n + 1, vector<pii>(n + 1, make_pair(0, 0)));\n p1[n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n bool predictTheWinner(vector<int>& nums) {\n int n = nums.size();\n int f[n][n];\n memset(f, 0, sizeof(f));\n function<int(int, int)> dfs = [&](int i, int j) -> int {\n if (i > j) {\n return 0;\n }\n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n bool predictTheWinner(vector<int>& nums) {\n // Observations:\n // - We can simulate the state of the game by (scoreA, who, from, to)\n // - The initial state would be: (0, A, 0, n-1)\n // - The final state would be: (scoreA, n % 2 ? Alice : Bob, k, k)\n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\nprivate:\n int solve(vector<int>& nums, int i, int j, bool player1,\n vector<vector<vector<int>>>& dp) {\n if (i > j) {\n return 0;\n }\n if (dp[i][j][player1] != -1)\n return dp[i][j][player1];\n\n if (player1) {\n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\n long long f(int i, int j, bool turn, vector<int> &nums, vector<vector<vector<long long>>> &dp)\n {\n if(i == j) \n {\n if(turn) return nums[i];\n return 0;\n }\n if(dp[i][j][turn] != -1) return dp[i][j][turn];\n if(turn)\n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\n long long f(int i, int j, bool turn, vector<int> &nums, vector<vector<vector<long long>>> &dp)\n {\n if(i == j) \n {\n if(turn) return nums[i];\n return 0;\n }\n if(dp[i][j][turn] != -1) return dp[i][j][turn];\n if(turn)\n ...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n int solve(vector<int>&nums,int i,int j,int turn,vector<vector<vector<int>>>&dp){\n if(i > j){\n return 0;\n }\n\n if(dp[i][j][turn] != -1){\n return dp[i][j][turn];\n }\n\n if(turn == 0){\n int ans1 = nums[i]...
486
<p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p> <p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en...
3
{ "code": "class Solution {\npublic:\n long long helper(vector<int>& nums, int turn, int l, int r, vector<vector<vector<int>>>& dp){\n if(l>r){\n return 0;\n }\n if(dp[l][r][turn]!=-1) return dp[l][r][turn];\n long long ans;\n if(turn==1){\n ans = max(nums[l...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "\nauto init = []() {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n char agearr[3];\n string line;\n while (std::getline(std::cin, line)) {\n std::istringstream input(line);\n int cnt = 0;\n input.ignore(13);\n while (!inpu...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "\nauto init = []() {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n char agearr[3];\n string line;\n while (std::getline(std::cin, line)) {\n std::istringstream input(line);\n int cnt = 0;\n input.ignore(13);\n while (!inpu...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid parse_input_and_solve(std::ofstream& out, s...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int ans = 0;\n for (auto& x : details) {\n int age = stoi(x.substr(11, 2));\n ans += age > 60;\n }\n return ans;\n }\n};", "memory": "17200" }
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int count = 0;\n int age = 0;\n for(string& str: details){\n age = ((str[11]) - '0') * 10 + str[12] - '0';\n \n age > 60? count++: NULL;\n }\n return count;\n }\n};...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int count =0;\n for(string& s : details){\n int age = (s[11] - '0')*10 + (s[12] - '0');\n if( age > 60)\n ++count;\n }\n return count;\n }\n};", "memory": "1740...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& v) {\nint c=0;\n for(int i=0;i<v.size();i++){\n int n=v[i].size();\n if((v[i][n-4]=='6'&&v[i][n-3]>='1')||(v[i][n-4]>='7')){\n c++;\n }\n }\n return c;\n }\n};", "me...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& v) {\n int count = 0; \n for(auto &x : v){\n int age = stoi(x.substr(11,2)) ;\n if(age > 60){\n count+=1 ;\n }\n }\n return count ;\n }\n};", "memory": "17500" }
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int count =0;\n for(string& s : details){\n int age = (s[11] - '0')*10 + (s[12] - '0');\n if( age > 60)\n ++count;\n }\n return count;\n }\n};", "memory": "1750...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n\n int n=details.size();\n int count=0;\n for(int i=0;i<n;i++)\n {\n string x=details[i];\n cout <<x.substr(11,2)<<endl;\n int age = stoi(x.substr(11,2));\n if(a...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
0
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int ans=0;\n for(int i=0;i<details.size();i++){\n int x=details[i][11]-48;\n int y=details[i][12]-48;\n int s=0;\n s=s*10 + x;\n s=s*10 + y;\n if(s>60...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
2
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int count = 0 ;\n for (int i=0; i<details.size(); i++){\n string detail = details[i] ;\n int age = (detail[11]-'0')*10 + (detail[12]-'0') ;\n if (age > 60) count++ ;\n }\n ...
2,727
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p> <ul> <li>The first ten characters consist of the phone number of passe...
2
{ "code": "class Solution {\npublic:\n int countSeniors(vector<string>& details) {\n int i,c=0;\n for (i=0;i<details.size();i=i+1)\n {\n if (stoi(details[i].substr(11,2))>60)\n {\n c=c+1;\n }\n }\n return c;\n }\n};", "memory":...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n if (n==1) return 1;\n return (findTheWinner(n-1,k)+k-1)%n+1;\n }\n};", "memory": "7200" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n int helper(int n,int k){\n if(n==1) return 0;\n return (helper(n-1,k) + k)%n;\n }\n\n int findTheWinner(int n, int k) {\n return helper(n,k)+1;\n }\n};", "memory": "7200" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n\n int findTheWinnerQueue(int n, int k) {\n std::queue<int> q;\n for (int i = 1; i <= n; i++) {\n q.push(i);\n }\n\n while (q.size() > 1) {\n for (int i = 1; i < k; i++) {\n q.push(q.front());\n q....
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n\n int winner(int n, int k) {\n if(n==1){\n return 0;\n }\n\n return (winner(n-1,k)+k)%n; \n }\n int findTheWinner(int n, int k){\n return winner(n,k)+1;\n }\n};", "memory": "7300" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n // f(n, k) = (f(n-1, k) + k) mod n\n int survivor = 0;\n for (int i = 2; i <= n; ++i) {\n survivor = (survivor + k) % i;\n }\n\n return ++survivor;\n }\n};", "memory": "7400" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n int winner=0;\n int i;\n for(i=1;i<=n;i++){\n winner=(winner+k)%i;\n \n\n }\n return winner+1;\n \n }\n};", "memory": "7400" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\nint winner(int n, int k)\n{\n if (n == 1)\n {\n // If only 1 member is left, it is treated as 0\n return 0;\n }\n // competitors are of range 0...n-1\n\n int x = winner(n - 1, k);\n int y = (x + k) % n;\n\n return y;\n}\nint findTheWinner(int n,...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
0
{ "code": "class Solution {\npublic:\n static int findTheWinner(int n, int k) {\n if (n==1) return 1;\n return (findTheWinner(n-1, k)+(k-1))%n+1;\n }\n};\n\n\n\n\nauto init = []() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();", "memory": "7500" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
1
{ "code": "class Solution {\n int find(int n, int k){\n\nif(n==1) return 0;\nreturn (find(n-1,k)+k)%n;\n }\npublic:\n int findTheWinner(int n, int k) {\n return find(n,k)+1;\n }\n};", "memory": "7600" }
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
1
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n vector<int> temp(n,1);\n int i = 0;\n int count = 0;\n int p = n-1;\n while(p>0){\n if(temp[i]==1){count++;}\n if(count == k){\n temp[i]=0;\n count = 0;\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
1
{ "code": "class Solution {\npublic:\nvoid friendEliminated(int *friends, int index)\n{\n friends[index] = INT32_MAX;\n}\nint numPlayers(int *friends, int size)\n{\n int count = 0, index;\n for (int i = 0; i < size; i++)\n {\n if (friends[i] != INT32_MAX)\n {\n index = friends[i];...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
1
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n int start=0;\n vector<int>v(n,-1);\n for(int i=0;i<n;i++)\n {\n v[i]=i+1;\n }\n while(v.size()!=1)\n {\n start=(start+k-1)%v.size();\n v.erase(v.begin()+start);\n } \n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
1
{ "code": "void solve(vector<int>& personArr,int k,int n,int index){\n // Base case \n if(personArr.size() == 1) return ;\n\n\n // Recurssive call \n \n int y=personArr.size();\n index=(index+(k-1)) % y ;\n \n \n personArr.erase(personArr.begin()+index);\n // for(int i=0;i<personArr.size(...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
1
{ "code": "void solve(vector<int>& personArr,int k,int n,int index){\n // Base case \n if(personArr.size() == 1) return ;\n\n\n // Recurssive call \n \n int y=personArr.size();\n index=(index+(k-1)) % y ;\n \n \n personArr.erase(personArr.begin()+index);\n // for(int i=0;i<personArr.size(...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "void solve(vector<int>& personArr,int k,int n,int index){\n // Base case \n if(personArr.size() == 1) return ;\n\n\n // Recurssive call \n \n int y=personArr.size();\n index=(index+(k-1)) % y ;\n \n \n personArr.erase(personArr.begin()+index);\n // for(int i=0;i<personArr.size(...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n vector<int> arr;\n for(int i=1;i<=n;i++)\n {\n arr.push_back(i);\n }\n for(int i=0;arr.size()!=1;)\n {\n i=(i+k-1)%arr.size();\n arr.erase(arr.begin()+i);\n\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n // Create a vector of friends numbered from 1 to n\n vector<int> friends;\n for (int i = 1; i <= n; i++) {\n friends.push_back(i);\n }\n \n int startIndex = 0;\n \n // Conti...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\n\n struct ListNode {\n int val;\n ListNode *next;\n ListNode() : val(0), next(nullptr) {}\n ListNode(int x) : val(x), next(nullptr) {}\n ListNode(int x, ListNode *next) : val(x), next(next) {}\n };\n \npublic:\n int solve(ListNode* curr,ListNode* prev,int k){\n\...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n struct ListNode {\n int val;\n ListNode *next;\n ListNode(int x) : val(x), next(NULL) {}\n };\n void solve(ListNode* temp, int &i, int k, int n)\n {\n // edge case\n if(n==1) return;\n\n // 1 case hm solve krenge\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n class Node {\n public:\n int val;\n Node *prev, *next;\n Node(int v) {\n val = v;\n }\n };\n\n int findTheWinner(int n, int k) {\n Node *head = new Node(1);\n Node *curr = head;\n\n f...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n list<int> friends;\n for(int i=1;i<=n;i++){\n friends.push_back(i);\n }\n auto it=friends.begin();\n while(friends.size()>1){\n for(int i=0;i<k-1;++i){\n ++it;\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n if(k==1 || n==1) \n return n;\n set<int> s;\n for(int i=1;i<=n;i++){\n s.insert(i);\n }\n auto it=s.begin();\n while(s.size()>1){\n for(int steps=1;steps<k;steps++)...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>&arr,int index,int n,int &k)\n {\n if(n==1)\n return index+1;\n\n int kill=k-1%n;\n\n for(int i=1;i<=kill;i++)\n {\n index=(index+1)%(arr.size()); \n while(arr[index])\n {\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>&arr,int index,int n,int &k)\n {\n if(n==1)\n return index+1;\n\n int kill=k-1%n;\n\n for(int i=1;i<=kill;i++)\n {\n index=(index+1)%(arr.size()); \n while(arr[index])\n {\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>&arr,int index,int n,int &k)\n {\n if(n==1)\n return index+1;\n\n int kill=(k-1)%n;\n\n while(kill--)\n {\n index=(index+1)%(arr.size()); \n while(arr[index])\n {\n ind...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n set<int> s;\n for(int i=1;i<=n;i++)\n {\n s.insert(i);\n }\n int c=0;\n int i=1;\n while(s.size()>1)\n {\n if(i>n)\n {\n i=i-n;\n }\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>&arr,int index,int n,int &k)\n {\n if(n==1)\n return index+1;\n\n int kill=(k-1)%n;\n\n while(kill--)\n {\n index=(index+1)%(arr.size()); \n while(arr[index])\n {\n in...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>&arr,int index,int n,int &k)\n {\n if(n==1)\n return index+1;\n\n int kill=(k-1)%n;\n\n for(int i=0;i<kill;i++)\n {\n index=(index+1)%(arr.size()); \n while(arr[index])\n {\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>&arr,int index,int n,int &k)\n {\n if(n==1)\n return index+1;\n\n int kill=(k-1)%n;\n\n for(int i=1;i<=kill;i++)\n {\n index=(index+1)%(arr.size()); \n while(arr[index])\n {\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n\n int winner( vector<bool>&person , int n , int index , int person_left , int k )\n {\n if(person_left==1)\n { \n for(int i=0;i<n;i++)\n if(person[i]==0)\n return i;\n }\n\n //find the position of Kill;\n\n int kill=(k-1)%p...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n \n std::vector<int> friends;\n for(int i = 1; i <=n; i++){\n friends.insert(friends.end(), i);\n }\n int pos = 0;\n\n while(friends.size() > 1){\n pos = pos + k - 1;\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n \n std::vector<int> friends;\n for(int i = 1; i <=n; i++){\n friends.insert(friends.end(), i);\n }\n int pos = 0;\n\n while(friends.size() > 1){\n pos = pos + k - 1;\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\n\npublic:\n int findTheWinner(int n, int k) {\n vector<int> li;\n for(int i=1;i<n+1;i++){\n li.push_back(i);\n }\n std::function<int(int,int)> recur = [&](int totp,int currp){\n if (totp<2){\n return li[0];\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\n int winner(vector<bool>&play,int &count,int &total,int k)\n{\n if(total==play.size()-1)\n {\n for(int i=0;i<play.size();i++)\n {\n if(play[i]==0)\n return i+1;\n }\n }\n \n for(int i=0;i<play.size();i++)\n {\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n std::unordered_set<int> losers;\n int start = 1;\n while (losers.size() < n) {\n int count = 0;\n int next_start = start;\n for (; count < k; next_start = (next_start + 1) % n) {\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n unordered_set<int> out;\n int idx = 0;\n while (out.size() < n-1) {\n int tmp = 0;\n while (tmp < k) {\n if (out.count(idx) ==0) {\n if (++tmp == k)\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n unordered_map<int,int> m;\n int s = 0;\n int cnt = 0;\n while(m.size()<n-1){\n int x = s%n+1;\n if(m.find(x)==m.end()) cnt++;\n if(cnt==k){\n cout<<x<<endl;\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n int N=n;\n vector<int>V;\n for(int i=1;i<=n;i++)\n {\n V.push_back(i);\n }\n map<int,int>M;\n int count=0;\n // int start=k-1;\n // while(1)\n // {\n //...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n\nusing namespace __gnu_pbds;\n#define ll long long\n\n\ntemplate<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;\n\nclass Solution {\npublic:\n int findTheWinner(int ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n deque<int> dq;\n for(int i=1;i<=n;i++)\n {\n dq.push_back(i);\n }\n int i=0;\n while(dq.size()!=1)\n {\n i=(i+k-1)%dq.size();\n dq.erase(dq.begin()+i);\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n deque<int> dq;\n for(int i=1;i<=n;i++)\n {\n dq.push_back(i);\n }\n int i=0;\n while(dq.size()!=1)\n {\n i=(i+k-1)%dq.size();\n dq.erase(dq.begin()+i);\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\nint winner(vector<bool>person,int n,int index,int person_left,int k)\n{\n if(person_left==1)\n {\n for(int i=0;i<n;i++)\n {\n if(person[i]==0)\n {\n return i+1;\n }\n }\n }\n\n int eliminate=(k-1)%pe...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>person, int n ,int index, int person_left, int k)\n {\n if(person_left==1)\n {\n for(int i=0; i<n; i++)\n {\n if(person[i]==0)\n return i;\n }\n }\n int kill=(...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>player,int n, int k, int index,int left){\n if(left == 1)\n {\n for(int i = 0; i < n; i++)\n if(player[i] == 0)\n return i;\n }\n int kill = (k-1)%left;\n while(kill--){\n in...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int winner(vector<bool>player,int n, int k, int index,int left){\n if(left == 1)\n {\n for(int i = 0; i < n; i++)\n if(player[i] == 0)\n return i;\n }\n int kill = (k-1)%left;\n while(kill--){\n in...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for (int i = 1; i <=n; i++) {\n q.push(i);\n }\n while(n>1){\n for(int i=0;i<(k%n-1+n)%n;i++){\n q.push(q.front());\n q.pop(); \n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for(int i = 1; i <= n; i++)\n q.push(i);\n while(q.size() > 1){\n int m = k % q.size();\n if(m == 0) m = q.size();\n int i = 1;\n while(i < m){\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for(int i = 1; i <= n; i++){\n q.push(i);\n }\n int a = k;\n while(q.size() >= 2){\n if(k % q.size() == 0){\n a = k;\n }\n else{\n...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for(int i = 1; i <= n; i++){\n q.push(i);\n }\n int a = k;\n while(q.size() >= 2){\n /*if(k > q.size()){\n a = k % q.size();\n }*/\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for (int i = 0; i<n; i++) {q.push(i+1);}\n while(q.size() > 1) {\n int c = 0;\n while (c < (k-1) % q.size()) {\n q.push(q.front());\n cout << q.back();...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for (int i = 0; i<n; i++) {q.push(i+1);}\n while(q.size() > 1) {\n int c = k;\n short s = q.size();\n while (0 < (c-1) % s) {\n q.push(q.front());\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for (int i = 0; i<n; i++) {q.push(i+1);}\n while(q.size() > 1) {\n int c = 0;\n short s = q.size();\n while (c < (k-1) % s) {\n q.push(q.front());\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> q;\n for (int i = 0; i<n; i++) {q.push(i+1);}\n while(q.size() > 1) {\n short c = k;\n short s = q.size();\n while (0 < (c-1) % s) {\n q.push(q.front());\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "//Burak Emre Polat\nclass Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<short> q;\n for (short i = 1; i<=n; i++) {q.push(i);}\n while(q.size() > 1) {\n for (short i = 1; i < k ; i++) {\n q.push(q.front());\n q.pop();\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "//Burak Emre Polat\nclass Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<short> q;\n for (short i = 1; i<=n; i++) {q.push(i);}\n while(q.size() > 1) {\n for (short i = 1; i < k ; i++) {\n q.push(q.front());\n q.pop();\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n deque <int> dq;\n for(int i=1;i<=n;i++){\n dq.push_back(i);\n }\n int p=0;\n while(dq.size()!=1){\n int h=dq.front();\n dq.pop_front();\n p++;\n p%=k;...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int>q;\n for(int i=1;i<=n;i++)q.push(i);\n while(q.size()>1){\n int val=k;\n while(--val){\n q.push(q.front());\n q.pop();\n }\n q.pop();\n...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "class Solution {\npublic:\n\n int findTheWinnerQueue(int n, int k) {\n std::queue<int> q;\n for (int i = 1; i <= n; i++) {\n q.push(i);\n }\n\n while (q.size() > 1) {\n for (int i = 1; i < k; i++) {\n q.push(q.front());\n q....
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
2
{ "code": "#include <queue>\nusing namespace std;\n\nclass Solution {\npublic:\n int findTheWinner(int n, int k) {\n queue<int> s;\n \n // Populate the queue with players from 1 to n\n for(int i = 1; i <= n; i++) {\n s.push(i);\n }\n \n // Simulate the el...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
3
{ "code": "class Solution {\npublic:\n \n int findTheWinner(int n, int k) {\n queue<int> q;\n for(int i=1; i<=n; i++){\n q.push(i);\n }\n while(q.size()>1){\n for(int i=1; i<k; i++){\n q.push(q.front());\n q.pop();\n }\n ...
1,951
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> frien...
3
{ "code": "class Solution {\npublic:\n queue<int>q;\n int findTheWinner(int n, int k)\n {\n for(int i=1;i<=n;i++)\n {\n q.push(i);\n }\n\n int cnt=0;\n while(q.size()>1)\n {\n int v=q.front();\n q.pop();\n cnt++;\n\n ...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string p) {\n int n=p.size();\n if(n==1) return \"\";\n //cout << 'z'-'a'<<endl;\n for(int i=0;i<n/2;i++){\n if(p[i]-'a'!=0) {\n p[i]='a';\n return p;\n }\n }\n ...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n if (palindrome.size() == 1) {\n return \"\";\n }\n\n for (int i = 0; i < palindrome.size(); ++i) {\n char& c = palindrome[i];\n if (c != 'a' && !(palindrome.size() % 2 == 1 && ...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n int length = palindrome.size();\n \n if (length == 1) { \n return \"\";\n }\n \n for (int i = 0; i < length / 2; i++) {\n if (palindrome[i] != 'a') {\n ...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n if (palindrome.size() == 1)\n {\n return \"\";\n }\n\n // We only have to look up to halfway into the palindrome, not inclusive of center character\n\n // Then we want to change the fi...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n int length = palindrome.size();\n \n if (length == 1) { \n return \"\";\n }\n \n for (int i = 0; i < length / 2; i++) {\n if (palindrome[i] != 'a') {\n ...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n int n = palindrome.size();\n if(n == 1)\n return \"\";\n \n int idx = -1;\n for(int i=0; i<n/2; i++) {\n if(palindrome[i] != 'a') {\n palindrome[i] = 'a';\n ...
1,252
<p>Given a palindromic string of lowercase English letters <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the resulting string is <strong>not</strong> a palindrome and that it is the <strong>lexicographically smallest</strong> one possible.</p> <p>Retu...
0
{ "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n int length = palindrome.size();\n \n if (length == 1) { \n return \"\";\n }\n \n for (int i = 0; i < length / 2; i++) {\n if (palindrome[i] != 'a') {\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int n = mat.size();\n int m = mat[0].size();\n\n \n for (int i = 0; i < n; i++) {\n int j = i, k = 0; \n bool swapped;\n do {\n swapped ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat){\n for(int k=0; k + 1 < mat.size(); k++){\n for(int i=0; i + 1 <mat.size();i++){\n for(int j=0; j + 1<mat[i].size();j++){\n if(mat[i][j] > mat[i + 1][j + 1]){\n ...
1,253
<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix&#39;s end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</cod...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n bool bubble = true;\n while (bubble) {\n bubble = false;\n for (int i = 0; i < m - 1; i++) {\n for (i...