id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n#define MOD 1000000007\n int numWays(int steps, int arrLen) {\n vector<int> dp(arrLen, 0);\n dp[0] = 1;\n vector<int> next_dp(arrLen, 0);\n\n for (int k = 1; k <= steps; k++) {\n for (int i = 0; i < arrLen && i < steps - k + 1; i++) {\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n\n int MOD = 1e9+7;\n\n int calculate(int currIndex, int arrLen, int stepsLeft, vector<vector<long long>> &dp){\n if(stepsLeft==0){\n if(currIndex==0){\n return 1;\n }\n return 0;\n }\n if(dp[currIndex][st...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& dp, int idx, int step, int steps, int maxs){\n if(idx==0 && step==steps)\n return 1;\n if(step>=steps || idx<0 || idx>=maxs || idx>=1000)\n return 0;\n if(dp[idx][step]!=-1)\n return dp[idx][...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& dp, int idx, int step, int steps, int maxs){\n if(idx==0 && step==steps)\n return 1;\n if(step>=steps || idx<0 || idx>=maxs || idx>=1000)\n return 0;\n if(dp[idx][step]!=-1)\n return dp[idx][...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int dp[501][10001];\n int f(int steps,int i,int arrLen)\n {\n if(i>=arrLen || i<0)\n {\n return 0;\n }\n if(steps==0)\n {\n return i==0;\n }\n if(i<1000 && dp[steps][i]!=-1)\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int dp[502][10005];\n int solve(int ind,int steps,int len){\n if(ind==0&&steps==0) return 1;\n if(steps==0) return 0;\n int mod=1e9+7;\n if(dp[ind][steps]!=-1) return dp[ind][steps];\n int ans=0;\n if(ind>0){\n ans=(ans+...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int dp[10010][505];\n int mod=1e9+7;\n int rec(int index,int pos,int &arrLen,int &steps){\n if(index < 0 || index >= arrLen){\n return 0;\n }\n if(pos == steps){\n if(index == 0){\n return 1;\n }\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n vector<vector<long long>> dp;\n int mod=1e9+7;\n long long solve(int i,int steps,int n){\n if(i<0 || i>=n) return 0;\n if(steps==0 && i!=0) return 0;\n if(steps==0 && i==0) return 1;\n if(dp[i][steps]!=-1) return dp[i][steps];\n long l...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\n const int MOD = 1e9 + 7;\npublic:\n int numWays(int steps, int n) {\n if (n == 1) return 1;\n vector<vector<int>> dp(2, vector<int>(n, 0));\n dp[0][0] = dp[0][1] = 1;\n\n for (int s=1; s<steps; ++s) {\n for (int i=0; i<min(n, steps); ++i) {\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\n const int MOD = 1e9 + 7;\npublic:\n int numWays(int steps, int n) {\n if (n == 1) return 1;\n vector<vector<int>> dp(2, vector<int>(n, 0));\n dp[0][0] = dp[0][1] = 1;\n\n for (int s=1; s<steps; ++s) {\n for (int i=0; i<min(n, s+2); ++i) {\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int generate(const int &arrLen, const int &endPos, const int &k, int i, int pos)\n {\n if (i == k)\n {\n return endPos == pos;\n }\n if ((pos - (k - i + 1)) > 0) return 0;\n \n int x1 = 0;\n if ((pos + 1) != arrLe...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int generate(const int &arrLen, const int &endPos, const int &k, int i, int pos)\n {\n if (i == k)\n {\n return endPos == pos;\n }\n if ((pos - (k - i + 1)) > 0) return 0;\n \n int x1 = 0;\n if ((pos + 1) != arrLe...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n\n struct pair_hash\n {\n template <typename T, typename U>\n std::size_t operator () (const std::pair<T, U> &x) const\n {\n return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);\n }\n };\n\n int numWays(int steps, int arrLe...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n unordered_map<int, int> v;\n int mod = 1e9+7;\n v[0] = 1;\n if(arrLen>=2){\n v[1] = 1;\n }\n for(int i=2;i<=steps; i++){\n unordered_map<int, int> tv = v;\n for(a...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\nint n,st;\nlong long dp[501][10001];\nlong long mod=1e9+7;\nlong long f(long long i,long long j){\n if(i==st) return (j==0);\n if(j<0 || j==n) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n long long ans=(f(i+1,j-1)+f(i+1,j+1)+f(i+1,j))%mod;\n return dp[i][j]=an...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int M = pow(10, 9) + 7;\n int ways(int steps, int pos, int len, vector<vector<int>> &dp){\n if(steps == 0 && pos == 0)\n return 1;\n if(steps == 0)\n return 0;\n\n if(dp[pos][steps] != -1)\n return dp[pos][steps];\n\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\n int N;\n int M=1e9+7;\n vector<vector<int>> dp;\n unordered_map<string, int> m;\n int check(int steps, int ind){\n if(steps==0){\n if(ind==0) return 1;\n return 0;\n }\n if(ind>=500) return 0;\n //string str=to_string(s...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\nint mod = 1000000007;\n\nint fn(int idx, int cnt, int len, int steps, int **dp) {\n\n if(idx<0 or idx>=len) {\n return 0;\n }\n if(cnt>=steps) {\n if(idx==0) {\n return 1;\n }\n return 0;\n }\n\n if(dp[idx][cnt]!=-1) return ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int check(vector<vector<int>>&dp,int index,int n,int k){\n if(index<0 || index==n){\n return 0;\n }\n if(k==0){\n return (index==0);\n }\n if(dp[index][k]!=-1){\n return dp[index][k];\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\n \npublic:\n int mod=1e9+7;\n long long solve(int ind, vector<vector<int>> &dp, int n, int steps){\n if(steps==0) return (ind==0);\n if(dp[ind][steps]!=-1) return dp[ind][steps];\n long long res=0;\n\n if(ind-1>=0){\n res+=solve(ind-1, dp, n...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\nprivate:\n int getNumWays(int currInd, int stepsLeft, int &arrLen, unordered_map<int, unordered_map<int, int>> &countWays) {\n if (stepsLeft == 0) return (currInd == 0);\n\n if (countWays[currInd].count(stepsLeft) == 1) return countWays[currInd][stepsLeft];\n\n // ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int md = 1e9+7;\n unordered_map<int, unordered_map<int, int>> dp;\n int solve(int k, int n, int i) {\n if (k==0) return (int)(i==0);\n if (dp.count(i) && dp[i].count(k)) return dp[i][k];\n int res=0;\n res = (res + solve(k-1, n, i))%md;\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, unordered_map<int, int>> dp;\n int MOD = pow(10, 9) + 7;\n int solve(int curr, int len, int rem){\n if(rem == 0){ \n if(curr == 0) return 1;\n else return 0;\n }\n if(dp.find(curr) != dp.end() && dp[curr].fin...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int generate(const int &arrLen, const int &endPos, const int &k, int i, int pos)\n {\n if (i == k)\n {\n return endPos == pos;\n }\n int x1 = 0;\n if ((pos + 1) != arrLen)\n {\n auto it = hash.find((100000*(po...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int generate(const int &arrLen, const int &endPos, const int &k, int i, int pos)\n {\n if (i == k)\n {\n //cout << \"In pos = \" << pos << endl;\n return endPos == pos;\n }\n int x1 = 0;\n if (pos < 0) return 0;\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "const int MOD = 1e9 + 7;\n\nclass Solution {\npublic:\n void add(int &x, int val){\n x += val;\n if(x > MOD){\n x -= MOD;\n }\n }\n\n int numWays(int steps, int arrLen) {\n map<int, int> mp;\n mp[0] = 1;\n for(int i = 0; i < steps; ++i){\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n map<pair <int, int> , int > dp;\n long long int mod = 1e9 + 7;\n int dfs(int index, int steps, int n) {\n if(index < 0 || index >= n) return 0;\n if(dp.find({index,steps}) != dp.end()) return dp[{index, steps}];\n if(steps == 0){\n retu...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n long MOD = 1000000007;\n long dfs(int i, int s, int al, map<pair<int, int>, long> &m){\n if(s == 0 && i == 0) return 1;\n if(i < 0 || i >= al || s == 0) return 0;\n if(m.find({i, s}) != m.end()) return m[{i, s}];\n return m[{i, s}] = (dfs(i, s -...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "static const int mod = 1000000007;\nclass Solution {\npublic:\n map<long long,long long> mm;\n long long f(long long steps,const int len,int pos){\n if(pos <= 0 || pos > len){\n return 0;\n }\n if(steps == 0){\n if(pos == 1) return 1;\n else retur...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n map<pair<int,int>,int> dp;\n int modu=1e9+7;\n int solve(int i , int steps, int arrlen){\n\n if(i==0 && steps==0) return 1;\n if(i<0 || steps==0 || i>=arrlen) return 0;\n if(dp.find({i,steps})!=dp.end()) return dp[{i,steps}];\n int a=solve(i+...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n\n int mod = 1e9+7;\n map<pair<int,int>,int> mp;\n\n int solve(int i,int steps,int n){\n if(i>=n || i<0) return 0;\n if(mp.find({i,steps})!=mp.end()) return mp[{i,steps}];\n if(steps==0) return i==0;\n int op1 = solve(i+1,steps-1,n) %mod;\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n map<pair<int, int>, int> mp;\n\n int solve(int i, int steps, int n) {\n if (i >= n || i < 0)\n return 0;\n\n if (mp.find({i, steps}) != mp.end())\n return mp[{i, steps}];\n\n if (steps == 0)\n re...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "int mod=1e9+7;\nclass Solution {\npublic:\n map<pair<int,int>,int>mp;\n int help(int level,int steps,int arrLen)\n {\n if(steps==0)\n {\n if(level==0)return 1;\n else return 0;\n }\n if(mp.find({level,steps})!=mp.end())return mp[{level,steps}];\n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int mod = 1000000007;\n int numWaysUtil(int startPos,int steps,map<int,map<int,int>>&dp,int &arrLen){\n if(steps==0){\n if(startPos==0)return 1;\n return 0;\n }\n if(dp.find(startPos)!=dp.end() && dp[startPos].find(steps) != dp[st...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n int mod = 1000000007;\n int numWaysUtil(int startPos,int steps,map<int,map<int,int>>&dp,int &arrLen){\n if(steps==0){\n if(startPos==0)return 1;\n return 0;\n }\n if(dp.find(startPos)!=dp.end() && dp[startPos].find(steps) != dp[st...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n\n struct pair_hash\n {\n template <typename T, typename U>\n std::size_t operator () (const std::pair<T, U> &x) const\n {\n return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);\n }\n };\n\n int numWays(int steps, int arrLe...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n\n struct pair_hash\n {\n template <typename T, typename U>\n std::size_t operator () (const std::pair<T, U> &x) const\n {\n return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);\n }\n };\n\n int numWays(int steps, int arrLe...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n\n struct pair_hash\n {\n template <typename T, typename U>\n std::size_t operator () (const std::pair<T, U> &x) const\n {\n return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);\n }\n };\n\n int numWays(int steps, int arrLe...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\nprivate:\n int mod = pow(10, 9)+7;\n int solve(int index, int steps, int& arrLen, unordered_map<long long int, unordered_map<long long int,long long int>>& dp){\n if(index<0 || index>=arrLen || steps<0)\n return 0;\n if(steps==0 && index==0)\n ret...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\npublic:\n long long int func(long long int ind, long long int steps, long long int len, map<pair<long long int, long long int>, long long int>& dp, long long int m) {\n if (ind == 0 && steps == 0) return 1;\n if (ind < 0 || ind >= len || steps < 0) return 0;\n \n ...
1,398
<p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <c...
3
{ "code": "class Solution {\n const int MOD = 1000000007;\n\npublic:\n int numWays(int steps, int arrLen) {\n vector<unordered_map<int, long long>> vec(steps);\n unordered_map<int, long long> mp, tp;\n mp[0] = 1;\n if(arrLen > 1)\n mp[1] = 1;\n vec[0] = mp;\n for...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
0
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n \n bool printOutput = false;\n char board[9];\n for(int i=0; i<9; i++)\n board[i]='_';\n\n for(int i=0; i<moves.size(); i++)\n {\n const int &currX = moves[i][0];\...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
0
{ "code": "class Solution {\npublic:\n\n //T O(n) S(9)\n string tictactoe(vector<vector<int>>& moves) {\n \n bool printOutput = false;\n char board[9];\n for(int i=0; i<9; i++)\n board[i]='_';\n\n for(int i=0; i<moves.size(); i++)\n {\n const int &...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
0
{ "code": "class Solution {\npublic:\n\n string tictactoe(vector<vector<int>>& moves) {\n \n vector<int> A_wins(8, 0), B_wins(8, 0);\n\n for(int i = 0; i < moves.size(); i ++){\n\n int row = moves[i][0], col = moves[i][1];\n\n if(i % 2 == 0){\n A_wins[row] ++...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
0
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n int n=3;\n vector<int> rows(n);\n vector<int> cols(n);\n int diag1 = 0;\n int diag2 = 0;\n int currPlayer = 1;\n\n for(vector<int> currMove : moves){\n \trows[currMove[0]] ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
0
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n vector<vector<char>> grid(3, vector<char>(3, ' '));\n \n \n for (int i = 0; i < moves.size(); ++i) {\n int row = moves[i][0], col = moves[i][1];\n if (i % 2 == 0) {\n g...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
0
{ "code": "class Solution {\npublic:\n int n;\n string tictactoe(vector<vector<int>>& moves) {\n\n vector<vector<int>> board(3, vector<int>(3, 0));\n int player = 1;\n n = moves.size();\n\n // Fill the board\n for (int i = 0; i < moves.size(); i++) {\n int x = moves...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
1
{ "code": "class Solution {\npublic:\n bool check(vector<vector<char>> &grid, char c) {\n for(int i=0; i<3; i++) {\n if(grid[i][0] == c && grid[i][1] == c && grid[i][2] == c) return true;\n if(grid[0][i] == c && grid[1][i] == c && grid[2][i] == c) return true;\n }\n\n if(...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
1
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n char grid[3][3], r, c;\n int m, n = 0, i;\n char ch;\n string a=\"A\", b=\"B\", draw=\"Draw\", pending=\"Pending\";\n for(i=0; i<moves.size(); i++){\n r = moves[i][0];\n ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
2
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) { \n int winner = checkWinner(moves);\n if (winner == 1 || winner == 2) { \n return winner == 1 ? \"A\" : \"B\";\n }\n\n if (moves.size() == 9) {\n return \"Draw\";\n ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n vector<vector<int>> board;\n for(int i = 0;i<3;i++){\n vector<int> vec;\n for(int j = 0;j<3;j++){\n vec.push_back(-1);\n }\n board.push_back(vec);\n ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n // Define all possible winning combinations\n vector<vector<int>> winner{{0,1,2},\n {3,4,5},\n {6,7,8},\n {0...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Solution {\npublic:\n string tictactoe(vector<vector<int>>& moves) {\n // Define all possible winning combinations\n vector<vector<int>> winner{{0,1,2},\n {3,4,5},\n {6,7,8},\n {0...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Solution {\npublic:\n bool hasWinner(string p1, string p2, string p3)\n {\n if(p1 == \"P\")\n return false;\n return p1 == p2 && p2 == p3;\n }\n\n string tictactoe(vector<vector<int>>& moves) {\n // create a matrix 3x3 with all elements equal to \"0\"\n ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Board {\nprivate:\nunordered_map<int, int> rows;\nunordered_map<int, int> cols;\nunordered_map<int, int> diags;\n\n/*\n0: left diag\n1: right diag\n2: both diags\n-1: not a diag\n*/\nint getDiag(int row, int col) {\n if (row == 1 && col == 1) return 2;\n if ((row == 0 && col == 0) || (row == 2 ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Board {\nprivate:\nunordered_map<int, int> rows;\nunordered_map<int, int> cols;\nunordered_map<int, int> diags;\n\n/*\n0: left diag\n1: right diag\n2: both diags\n-1: not a diag\n*/\nint getDiag(int row, int col) {\n if (row == 1 && col == 1) return 2;\n if ((row == 0 && col == 0) || (row == 2 ...
1,400
<p><strong>Tic-tac-toe</strong> is played by two players <code>A</code> and <code>B</code> on a <code>3 x 3</code> grid. The rules of Tic-Tac-Toe are:</p> <ul> <li>Players take turns placing characters into empty squares <code>&#39; &#39;</code>.</li> <li>The first player <code>A</code> always places <code>&#39;X&#3...
3
{ "code": "class Solution {\npublic:\n enum Type {\n Row0,\n Row1,\n Row2,\n Col0,\n Col1,\n Col2,\n Diag0,\n Diag1,\n };\n\n std::unordered_map<Type, int> playerA;\n std::unordered_map<Type, int> playerB;\n \n std::unordered_map<Type, int>* pl...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n bool isVowel(char s){\n return s=='A' || s=='E' || s=='I' || s=='O' || s=='U' || s=='a' || s=='e' || s=='i' || s=='o' ||s=='u';\n }\n\n int find(vector<int>& a){\n for(int i=0;i<a.size();i++){\n if(a[i]>0){\n return i;\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n const auto is_vowel = [](auto c) {\n return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'\n || c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';\n };\n int freq[10];\n for...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution{\n string sortedVowels = \"AEIOUaeiou\";\n\n inline int sortedVowelsIdx(const char& ch){\n return sortedVowels.find(ch);\n }\n\npublic:\n string sortVowels(string str){\n vector<int> vowelsCount(10);\n for(char& ch:str){\n int idx = sortedVowelsIdx...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n bool isVowel(char letter) {\n return letter == 'a' ||\n letter == 'e' ||\n letter == 'i' ||\n letter == 'o' ||\n letter == 'u' ||\n letter == 'A' ||\n letter == 'E' ||\n l...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> arr(10, 0);\n vector<char> v = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};\n for(int i = 0; i < s.size(); i++) {\n if(s[i] == 65) {\n arr[0]++;\n s[i] = '.';\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\n inline bool isvowel(char c) {\n c = tolower(c);\n return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';\n }\n\npublic:\n string sortVowels(string s) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n\n int daa[10] = {0};\n strin...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n bool isVowel(char c) {\n return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || \n c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';\n }\n string sortVowels(string s) {\n string t;\n t.reserve(s.size());\n for (...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n int n=s.size();\n vector<int> hash(58,0);\n for(int i=0;i<n;i++){\n int ch=s[i];\n if(ch == 'a' ||ch == 'e' ||ch == 'i' ||ch == 'o' ||ch == 'u' ||ch == 'A' ||ch == 'E' ||ch == 'I' ||ch == 'O' ||ch == '...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n bool isvowel(char &ch){\n return (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');\n }\n string sortVowels(string s) {\n map<char, int> m;\n for(int i = 0; i < s.size();...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string vow;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')\n vow+=s[i];\n }\n sort(vow.begin(),...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "#include <algorithm>\n#include <cctype> // for tolower\n#include <string>\n\nclass Solution {\npublic:\n bool isVowel(char ch) { // Changed function name from isvovel to isVowel\n char temp = tolower(ch);\n return temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u';\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char> vec;\n for(int i = 0; i < s.length(); i++) {\n if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' ||\n s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\nbool isVowel(char ch){\n if(ch=='A' || ch=='E'|| ch=='I' ||ch=='O'||ch=='U')\n return true;\n if(ch=='a' || ch=='e'|| ch=='i' ||ch=='o'||ch=='u')\n return true;\n return false;\n}\n string sortVowels(string s) {\n vector<char> vowels;\n for(int...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char>v;\n for(auto x:s){\n if(x=='A' || x=='E' || x=='I' || x=='O' || x=='U' || x=='a'|| x=='e' || x=='i'||x=='o' || x=='u'){\n v.push_back(x);\n }\n }\n sort(v.begin(),v....
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char> ans;\n for (int i=0;i<s.size();i++){\n if(s[i]=='A'|| s[i]=='E'|| s[i]=='I'|| s[i]=='O'|| s[i]=='U'|| s[i]=='a'|| s[i]=='e'|| s[i]=='i'|| s[i]=='o'|| s[i]=='u'){\n ans.push_back(s[i]);\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
0
{ "code": "class Solution\n{\npublic:\n string sortVowels(string s)\n {\n vector<char> vowels;\n for (int i = 0; i < s.size(); i++)\n {\n if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n bool isVowel(char ch){\n if(ch=='a'|| ch=='e'|| ch=='i' || ch=='o' || ch=='u'\n || ch=='A'|| ch=='E'|| ch=='I' || ch=='O' || ch=='U'){\n return true;\n }\n\n return false;\n }\n string sortVowels(string s) {\n string t ;\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n bool isVowel(char ch) {\n ch = tolower(ch);\n return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');\n }\n \n string sortVowels(string s) {\n unordered_map<char, int> mp;\n \n for(char &ch : s) {\n if(isV...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char> vowels{'a', 'e', 'i', 'o', 'u'};\n vector<char> temp;\n for(const char& c :s){\n char c2 = tolower(c);\n\n for(const char& v: vowels){\n if(c2 == v){\n te...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<char>v;\n for(int i=0;i<s.size();i++)\n {\n char p=s[i];\n if(p=='a' || p=='e' || p=='i' || p=='o' || p=='u' || p=='A' || p=='E' || p=='I' || p=='O' || p=='U')\n {\n v....
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string small=\"aeiou\";\n string cap=\"AEIOU\";\n int ind=0;\n string temp=\"\";\n for(int i=0;i<s.size();i++){\n for(auto x:small){\n if(s[i]==x)\n temp.push_back(s[i]...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string ans=\"\";\n vector<char>temp;\n for(auto i : s){\n if(i=='a'|| i=='e'||i=='o' ||i=='u'||i=='i'||i=='A'||i=='E'||i=='O'||i=='I'||i=='U'){\n temp.push_back(i);\n }\n }\n sort(temp.begin(),t...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string vowel;\n int lower[26];\n int upper[26];\n for(int i = 0;i<26;i++){\n lower[i] = upper[i] = 0;\n }\n for(int i = 0;i<s.size();i++){\n if(s[i] == 'a' || s[i] == 'e' || s[i] =...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n int lower[26];\n int upper[26];\n for(int i = 0;i<26;i++){\n lower[i] = upper[i] = 0;\n }\n for(int i = 0;i<s.size();i++){\n if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n int arr[58] = {0};\n\n int n = s.size();\n for (int i = 0; i < n; i++) {\n if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' ||\n s[i] == 'U' || s[i] == 'a' || s[i] == 'e' || s[i] == 'i'...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n \n\n int lower[26] = {0}; \n int upper[26] = {0};\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i] =='e'|| s[i]=='i' || s[i]=='o' || s[i]=='u'){\n lower[s[i]-'a']++;\n s...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string check =\"AEIOU\";\n\n int lower[26] = {0}; \n int upper[26] = {0};\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i] =='e'|| s[i]=='i' || s[i]=='o' || s[i]=='u'){\n lower[s[i]-'a'...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string check =\"AEIOU\";\n\n int lower[26] = {0}; \n int upper[26] = {0};\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i] =='e'|| s[i]=='i' || s[i]=='o' || s[i]=='u'){\n lower[s[i]-'a'...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0);\n int vowelcount=0;\n string temp=\"\";\n int j=0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='o'||s[i]=='u'||s[i]=='i')...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n // Returns true if the character is a vowel.\n bool isVowel(char c) {\n return c == 'a' || c == 'e' || c == 'o'|| c == 'u'|| c == 'i' \n || c == 'A' || c == 'E' || c == 'O'|| c == 'U'|| c == 'I';\n }\n\n string sortVowels(string s) {\n string...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n\n vector<int> lower(26, 0);\n vector<int> upper(26, 0);\n\n for (int i = 0; i < s.size(); i++) {\n if (s[i] == 'a' || s[i] =='e' ||s[i]=='i' || s[i]=='o' || s[i]=='u')\n {\n lower[s[i] -...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> lower(26, 0);\n vector<int> upper(26, 0);\n for(int i = 0; i < s.size(); i++)\n {\n if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')\n {\n l...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0);\n string ans;\n\n for(int i=0;i<s.size();i++){\n // wasey first upper then lower\n if(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'){\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0);\n string ans;\n\n for(int i=0;i<s.size();i++)\n {\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')\n {\n lower[s[i]-'a']++;\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
1
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> upper(26, 0);\n vector<int> lower(26, 0);\n\n for(int i=0; i<s.size(); i++){\n char c = s[i];\n //uppercase walo ko vector me dalo\n if(c=='A' || c=='E' || c=='I' || c=='O' || c=...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
2
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> lower(26,0);\n vector<int> upper(26,0);\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'||s[i]=='e'|| s[i]=='i'|| s[i]=='o'|| s[i]=='u'){\n lower[s[i]-'a']++;\n s[i]='#';\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
2
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0);\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){\n lower[s[i]-'a']++;\n s[i]='#';\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
2
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int>lower(26,0);\n vector<int>upper(26,0);\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'|| s[i]=='e' || s[i]=='i' ||s[i]=='o' ||s[i]=='u'){\n lower[s[i]-'a']++;\n s[i]='#';\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
2
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n vector<int> lower(26,0);\n vector<int> upper(26,0);\n\n for(int i=0;i<s.size();i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){\n lower[s[i]-'a']++;\n s[i]='#';\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
3
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string vowels;\n for (auto it : s) {\n if (it == 'a' || it == 'e' || it == 'i' || it == 'o' || it == 'u' ||\n it == 'A' || it == 'E' || it == 'I' || it == 'O' || it == 'U') {\n vowels.push_...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
3
{ "code": "class Solution {\npublic:\n string sortVowels(string s) \n {\n vector<int>lower(26,0),upper(26,0);\n string temp=\"\";\n for(int i=0;i<s.size();i++)\n {\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')\n lower[s[i]-'a']++;\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
3
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string help=\"\";\n string ans=\"\";\n vector<int> lower(26,0);\n vector<int> upper(26,0);\n for(int i=0;i<s.length();i++)\n {\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')\n ...
2,887
<p>Given a <strong>0-indexed</strong> string <code>s</code>, <strong>permute</strong> <code>s</code> to get a new string <code>t</code> such that:</p> <ul> <li>All consonants remain in their original places. More formally, if there is an index <code>i</code> with <code>0 &lt;= i &lt; s.length</code> such that <code>s...
3
{ "code": "class Solution {\npublic:\n string sortVowels(string s) {\n string help=\"\";\n string ans=\"\";\n vector<int> lower(26,0);\n vector<int> upper(26,0);\n for(int i=0;i<s.length();i++)\n {\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')\n ...