id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid)\n {\n stack<tuple<int, int, int, int>> *stk;\n stack<pair<int, int>> *vstd;\n int dirs[4][2] = { { -1, 0 }, { 0, 1 },\n { 1, 0 }, { 0, -1 } };\n int d, i, j, k, l, m, ... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid)\n {\n stack<tuple<int, int, int, int>> *stk;\n stack<pair<int, int>> *vstd;\n int dirs[4][2] = { { -1, 0 }, { 0, 1 },\n { 1, 0 }, { 0, -1 } };\n int d, i, j, k, l, m, ... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<int> goldBuckets = {};\n for (int i = 0; i < grid.size(); i++) {\n for (int j = 0; j < grid[0].size(); j++) {\n if (grid[i][j] != 0) {\n collectGold(goldBuckets... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "class Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<int> goldBuckets = {};\n for (int i = 0; i < grid.size(); i++) {\n for (int j = 0; j < grid[0].size(); j++) {\n if (grid[i][j] != 0) {\n collectGold(goldBuckets... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "class Solution {\n int countIfNoZeroes(vector<vector<int>> & grid){\n int n=grid.size(), m=grid[0].size();\n int count=0;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j]==0) return 0;\n count+=grid[i][j];\n }\n ... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "class Solution {\n int countIfNoZeroes(vector<vector<int>> & grid){\n int n=grid.size(), m=grid[0].size();\n int count=0;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j]==0) return 0;\n count+=grid[i][j];\n }\n ... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "using pt = pair<int, int>;\nusing ppt = pair<pt, int>;\n\nconst int dx[] = {-1, 0, 0, 1};\nconst int dy[] = {0, -1, 1, 0};\n\nint dp[1 << 25];\n\nclass Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<pt> gpositions;\n vector<int> weight;\n int n = grid... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "using pt = pair<int, int>;\n\nconst int dx[] = {-1, 0, 0, 1};\nconst int dy[] = {0, -1, 1, 0};\n\nbool reach[1 << 25];\nint dp[1 << 25];\n\nclass Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<pt> gpositions;\n vector<int> weight;\n int n = grid.size(... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "using pt = pair<int, int>;\n\nconst int dx[] = {-1, 0, 0, 1};\nconst int dy[] = {0, -1, 1, 0};\n\nbool reach[1 << 25];\nint dp[1 << 25];\n\nclass Solution {\npublic:\n int getMaximumGold(vector<vector<int>>& grid) {\n vector<pt> gpositions;\n vector<int> weight;\n int n = grid.size(... |
1,331 | <p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will ... | 3 | {
"code": "typedef struct{\n int x;\n int y;\n}move_t;\n\nclass Solution {\npublic:\n\n //per ogni x e y differente d\n\n void dfs(int sum,int x,int y,vector<vector<bool>> &V,vector<vector<int>> &grid,int &max_sum){\n\n vector<move_t> candidates;\n \n move_t m;\n if((x+1)<=grid... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 0 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n int MOD =int(1e9 + 7);\n long a=1,e=1,i=1,o=1,u=1,a_new,e_new,i_new,o_new,u_new;\n for(int j=2;j<n+1;j++){\n a_new=e;\n e_new=(a+i)%MOD;\n i_new=(a+e+o+u)%MOD;\n o_new=(i+u)%... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n const long long MOD = (long long) 1e9 + 7;\n \n \n \n long long countVowelPermutation(long long n) {\n long long dp[n + 3][30];\n memset(dp, 0, sizeof dp);\n \n string s = \"aeiou\";\n \n for(auto i : s) {\n dp[1][... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n long long dp[20000][5];\n int n;\n const int MOD = 1000000007;\n \n unordered_map<char, int> ind;\n \n long long recurse(int i, char c) {\n if (i == n-1) return 1;\n int d = ind[c];\n if (dp[i][d]) return dp[i][d];\n \n if ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int dp[20001][27];\n unordered_map<char,vector<char>> mp;\n int mod = 1e9+7;\n\n int solve(int n, int len, char last){\n if(len == n) return 1;\n\n if(dp[len][last-'a'] != -1) return dp[len][last-'a'];\n\n int res = 0;\n\n for(char &c : mp... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n unordered_map<char, vector<char>> map = {\n {'a', vector<char>({'e'})},\n {'e', vector<char>({'a', 'i'})},\n {'i', vector<char>({'a', 'e', 'o', 'u'})},\n {'o', vector<char>({'i', 'u'})},\n {'u', vector<char>({'a'})}\n };\n\n int dp[200... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int dp[26][20001];\n map<char, vector<char>> m;\n vector<char> &next(char c) {\n return m[c];\n }\n\n int find(char c, int n) {\n if (n == 1) {\n return 1;\n }\n if (dp[c - 'a'][n] != -1) {\n return dp[c - 'a'][n];... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n int m = 1e9+7;\n vector<int>a(n,0);\n vector<int>e(n,0);\n vector<int>i(n,0);\n vector<int>o(n,0);\n vector<int>u(n,0);\n a[0] = 1;\n e[0] = 1;\n i[0] = 1;\n o[0] = 1;\n... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<int>> DP(5,vector<int>(n,0));\n int mod = pow(10,9) + 7;\n for(int i=0;i<5;i++)\n DP[i][0] =1;\n //DP[i][k] is the number of permutations of length k-1 , starting with i(0-a,1-e..)\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int m=1e9+7;\n int solve(int prev,int n,vector<vector<int>> &dp){\n if(n==0){\n return 1;\n }\n if(dp[prev][n]!=-1){\n return dp[prev][n];\n }\n int ans=0;\n if(prev==0){\n ans=ans%m+solve(1,n-1,dp)... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int m = 1e9+7; \n vector<char> vec = {'a', 'e', 'i', 'o', 'u'};\n vector<vector<int>> memo;\n int a = 0, e = 1, i = 2, o = 3, u = 4;\n\n int solve(int idx, int n) {\n if (memo[idx][n] != -1)\n return memo[idx][n];\n \n if (n == 1)\n... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "const int mod=1e9+7;\nclass Solution {\nprivate:\n int func(int n, int x,vector <vector <int>> &dp ){\n if(n==1){\n return 1;\n }\n if(dp[x][n]!=-1){\n return dp[x][n]%mod;\n }\n if(x==0){\n return dp[x][n]=func(n-1, 1,dp)%mod;\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\n // 0 --> a\n // 1 --> e\n // 2 --> i\n // 3 --> o\n // 4 --> u\n\n int mod = 1e9 + 7;\n long long solve(int prev, int n, vector<vector<int>>& dp)\n {\n if(n == 0)\n {\n return 1;\n }\n\n if(dp[prev+1][n] != -1)\n {\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": " // Cases - just write down using recursion \n // Case 1. Each vowel 'a' may only be followed by an 'e'.\n // Case 2. Each vowel 'e' may only be followed by an 'a' or an 'i'.\n // Case 3. Each vowel 'i' may not be followed by another 'i'.\n // Case 4. Each vowel 'o' may o... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n const int mod = 1e9+7;\n\n int solve(int num, int index, int n, unordered_map<int,vector<int>> &mp, vector<vector<int>> &dp)\n {\n if(index>=n)\n return 1;\n\n if(dp[num][index]!=-1)\n return dp[num][index];\n\n int ans = 0;\n f... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n const int mod = 1e9+7;\n\n int solve(int num, int index, int n, unordered_map<int,vector<int>> &mp, vector<vector<int>> &dp)\n {\n if(index>=n)\n return 1;\n\n if(dp[num][index]!=-1)\n return dp[num][index];\n\n int ans = 0;\n f... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n vector<char>v={'a','e','i','o','u'};\n map<char,int>index;\n\n int mod=1e9+7;\n\n vector<vector<int>>dp;\n int solution(map<char,vector<char>>&mpp,int pi,int n){\n\n if(n==0){\n return 1;\n }\n if(pi==-1){\n int ans=0;\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n\n int mod = 1e9+7;\n int countVowelPermutation(int n) {\n if(n==1)\n return 5;\n\n vector<vector<long long>> dp(5,vector<long long>(n,0));\n long long sum = 0;\n\n for(int i=0;i<5;i++){\n dp[i][0] = 1;\n }\n\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "#define MOD 1000000007\nclass Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<long long int>> dp(5,vector<long long int>(n,0));\n for(int i=0;i<5;i++){\n dp[i][0]=1;\n }\n for(int i=1;i<n;i++){\n dp[0][i]=dp[1][i-1];\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n int MOD=1e9+7;\n vector<int> dp(5, 1);\n for (int i = 2; i <= n; ++i) {\n vector<int> new_dp(5, 0);\n new_dp[0] = dp[1]; \n new_dp[1] = (dp[0] + dp[2]) % M... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<int> > g = {{1}, {0, 2}, {0, 1, 3, 4}, {2, 4}, {0}};\n vector<int> dp(5, 1);\n const int Mod = 1e9 + 7;\n\n for (int i = 1; i < n; i++) {\n vector<int> new_dp(5);\n for (int u... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\n // 0 --> a\n // 1 --> e\n // 2 --> i\n // 3 --> o\n // 4 --> u\n\n int mod = 1e9 + 7;\n long long solve(int prev, int n, vector<vector<int>>& dp)\n {\n if(n == 0)\n {\n return 1;\n }\n\n if(dp[prev+1][n] != -1)\n {\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\n // 0 --> a\n // 1 --> e\n // 2 --> i\n // 3 --> o\n // 4 --> u\n\n int mod = 1e9 + 7;\n long long solve(int prev, int n, vector<vector<int>>& dp)\n {\n if(n == 0)\n {\n return 1;\n }\n\n if(dp[prev+1][n] != -1)\n {\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n long long dp(int curChar, int strLenSoFar, int maxStrLen, vector<vector<long long>>& memo) {\n if (strLenSoFar == maxStrLen) {\n return 1;\n }\n\n if (memo[curChar][strLenSoFar] != -1) {\n return memo[curChar][strLenSoFar];\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n long long dp(int curChar, int strLenSoFar, int maxStrLen, vector<vector<long long>>& memo) {\n if (strLenSoFar == maxStrLen) {\n return 1;\n }\n\n if (memo[curChar][strLenSoFar] != -1) {\n return memo[curChar][strLenSoFar];\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n const int MODULO = 1e9 + 7;\n\n std::vector<long long> nowVowels(5, 1);\n while (--n){\n std::vector<long long> nextVowels(5);\n nextVowels[0] = (nowVowels[1] + nowVowels[2] + nowVowels[4]) % MODU... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n const int MOD = 1e9 + 7;\n vector<long long> dp(5, 1);\n for (int length = 2; length <= n; ++length) {\n vector<long long> new_dp(5, 0);\n new_dp[0] = (dp[1]) % MOD;\n new_dp[1] = (dp[0... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n const int MOD = 1e9 + 7; // Modulo value\n\n // dp arrays for each vowel: a, e, i, o, u\n vector<long long> dp(5, 1); // Base case: for length 1, there's exactly one way to end with each vowel.\n\n // Iterate ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<int>> dp(n, vector<int>(5)); \n for (int i=0; i<5; i++)\n dp[0][i] = 1; \n \n int M = 1e9+7; \n \n for (int i=1; i<n; i++) {\n dp[i][0] = ((dp[i-1][1]+dp[i-1][2]... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base :: sync_with_stdio( false );\n cin.tie( nullptr ) , cout.tie( nullptr );\n }\n int countVowelPermutation(int n) {\n vector< vector< int>> dp( n , vector< int >(5 , 0) );\n for(int i=0 ; i<5 ; i++) {\n dp[0][... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 1 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<int>> dp(n+1,vector<int>(5,0));\n for(int i=0; i<5; i++) dp[1][i] = 1;\n int N = 1e9+7;\n for(int i=2; i<=n; i++){\n dp[i][0] = ((dp[i-1][4]+dp[i-1][1])%N + dp[i-1][2])%N;\n d... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 2 | {
"code": "class Solution {\npublic:\n int mod=1000000007;\n // int dfs(int n,char prev, unordered_map<char,vector<char>>& allowed,vector<vector<int>>& dp)\n // {\n // if(n==0)\n // return 1;\n // if(n<0)\n // return 0;\n // if(dp[n][prev-'a']==-1)\n // {\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 2 | {
"code": "class Solution {\nprivate:\n#define mod 1000000007\nint solve(int n , int ch , int size , vector<vector<int>> &dp){\n if(size>n){\n return 0;\n }\n if(size==n){\n return 1;\n }\n if(dp[size][ch] != -1){\n return dp[size][ch];\n }\n int ans = 0;\n if(size==0){\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 2 | {
"code": "class Solution {\n unordered_map<char, vector<char>> nextChar;\n unordered_map<char, int> charMap;\n int MOD = 1e9+7;\n\n vector<vector<int>> dp;\n\npublic:\n Solution(){\n charMap['a'] = 0;\n charMap['e'] = 1;\n charMap['i'] = 2;\n charMap['o'] = 3;\n char... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 2 | {
"code": "class Solution {\nprivate:\n int mod = pow(10, 9)+7;\n void solve(int n, int last, long long& count, vector<vector<int>>& dp){\n if(n==0){\n count = (count+1)%mod;\n return;\n }\n if(dp[n][last] != -1){\n count = (count+dp[n][last])%mod;\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 2 | {
"code": "class Solution {\nprivate:\n\nunordered_map<char, int> intFromChar;\nint modulo;\n\npublic:\n int countVowelPermutation(int n) {\n intFromChar['a'] = 0;\n intFromChar['e'] = 1;\n intFromChar['i'] = 2;\n intFromChar['o'] = 3;\n intFromChar['u'] = 4;\n modulo = 1e... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 2 | {
"code": "class Solution {\npublic:\n const int MOD = 1e9 + 7;\n\n int charToIndex(char c) {\n switch(c) {\n case 'a': return 0;\n case 'e': return 1;\n case 'i': return 2;\n case 'o': return 3;\n case 'u': return 4;\n default: return -1;... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dp;\n map<int,vector<int>> mp;\n int M=1e9+7;\n int solve(int i, int prev,int n){\n if(i==n) return 1;\n if(dp[i][prev]!=-1) return dp[i][prev];\n int ans=0;\n for(int v:mp[prev]){\n ans=(ans+solve(i+1,v,n... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int MOD=1e9+7;\n \n int solve(char ch, int n, vector<vector<int>>& dp) {\n if (n == 0) {\n return 1;\n }\n if (dp[ch - 97][n] != -1) {\n return dp[ch - 97][n];\n }\n \n int result = 0;\n if (ch == 'a... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int mod=1000000007;\n long long func (int i,int prev,int n,vector <vector <long long > >& dp){\n if (i==n)return 1;\n if (dp[i][prev]!=-1)return dp[i][prev];\n if (prev==0){\n return dp[i][prev]=func(i+1,1,n,dp)%mod;\n }\n if ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution \n{\npublic:\n int mod = 1e9 + 7;\n long long int f(int i, int n, int prev, vector<vector<long long int>> &dp)\n {\n if(i >= n) return 1 % mod;\n if(dp[i][prev+1] != -1) return dp[i][prev+1] % mod;\n long long int ans = 0;\n if(prev == -1) for(int ind = 0... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n#define long long int\nconst int MOD=1e9+7;\nint f(int i,int p,int n,unordered_map<int,vector<int>>&mp,vector<vector<int>>&dp){\n if(i==n){\n return 1;\n }\n if(dp[i][p]!=-1){\n return dp[i][p];\n }\n int t=0;\n if(p==6){\n for(int j=1;j<6;j++){... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n long long int dp[200001][26];\n int mod=1e9+7;\n vector<char> v = {'a','e','i','o','u'};\n long long int f(int i,char pre,int n){\n if(i==n){\n return 1;\n }\n if(dp[i][pre-'a']!=-1){\n return dp[i][pre-'a'];\n }\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n \n int MOD = 1000000007;\n \n \n int recurse(char x, int n, vector<vector<int>>& dp) {\n \n if(n == 1) return 1;\n if(dp[x-'a'][n] != -1) return dp[x-'a'][n];\n \n int temp = 0;\n if(x == 'a') {\n temp = (temp %... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dp;\n long long dpf(char a,int i,int n){\n if(i==n) return 1;\n if(dp[a-'a'][i]!=-1) return dp[a-'a'][i];\n \n\n long long c=0;\n if(a=='a') c+=dpf('e',i+1,n);\n if(a=='e') c+=dpf('a',i+1,n) + dpf('i',i+1,n);\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n long long fun(map<char,vector<char>>&mp,char prev,int index,int n,vector<vector<int>>&dp){\n if(index == n){\n return 1;\n }\n if(dp[prev-'a'][index]!=-1){\n return dp[prev-'a'][index];\n }\n long long count = 0;\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\nint solve( int prev, int n, vector<char>&v, vector<vector<int>>&mem){\n if(n==0){\n return mem[n][prev+1]= 1;\n }\n if(mem[n][prev+1] != -1){\n return mem[n][prev+1];\n }\n int ans =0;\n for(int i=0; i<5; i++){\n if(prev ==-1){\n a... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\n vector<vector<int>> memo;\n const int MOD = 1000000007;\n \n int countAll(int n, int pChar){\n if( n == 0){ return 1;}\n if(memo[n][pChar] == -1){\n int count = 0;\n if( pChar == 0){\n count = ((countAll(n-1, 1) + countAll(n-... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n const int MOD = 1e9 + 7;\n\n int countVowelPermutation(int n) {\n vector<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n vector<vector<int>> dp(n + 1, vector<int>(26, 0));\n\n // Base case: at length 1, each vowel has 1 permutation\n for (int i = 0;... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "// #2 Class to implement the Bottom-up approach:\nclass Solution {\n vector<char> vowels = {'a','e','i','o','u'};\n const int MOD = 1e9+7;\n\npublic:\n // #1 Method to count how many such strings of length n that can be formed, using 2D tabulation - O(N*23*5) & O(N*26)\n int countVowelPermutati... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "int m = 1e9 + 7;\n\nclass Solution {\npublic:\n int f(int ind, char ch, int n, vector<vector<int>> &dp) {\n if (ind == n) { \n return 1;\n }\n if(dp[ind][ch-'a'] != -1) return dp[ind][ch-'a'];\n \n int ans = 0; // Use int but be careful with modulo during a... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n const long long MOD = 1000000000 + 7;\n\n vector<vector<int>> dp;\n\n long long dfs(int charactersLeft, char lastChar) {\n if(charactersLeft == 0) return 1;\n\n if(dp[charactersLeft][lastChar - 'a'] != -1) {\n return dp[charactersLeft][lastChar ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic: \n vector<char> lst = {'a', 'e', 'i', 'o', 'u'};\n\n bool okA(char c){\n return c == 'e';\n }\n\n bool okE(char c){\n return c == 'a' || c == 'i';\n }\n\n bool okI(char c){\n return c != 'i';\n }\n\n bool okO(char c){\n return c ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\nprivate:\n int mod = 1000000007;\n int func(int index, char pre, int n, vector<vector<int>> &dp) {\n if(index == n) return 1;\n else if(index > n) return 0;\n if(dp[index][pre - '`'] != -1) return dp[index][pre - '`'];\n int op1 = 0, op2 = 0, op3 = 0, op4... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n // char vowels[]={'a','e','i','o','u'};\n int mod=1e9+7;\n int func(int ind,int n,char prev,vector<vector<int>> &dp)\n {\n if(ind==n)\n {\n return 1;\n }\n\n int ways=0;\n if(dp[ind][prev-'a']!=-1)\n {\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\nint mod=pow(10,9)+7;\n int func(int n, char ch,vector<vector<int>>&dp){\n if(n==0) return 1;\n if(dp[n][ch-'a']!=-1) return dp[n][ch-'a'];\n if(ch=='a'){\n return dp[n][ch-'a']=((long long int)func(n-1,'e',dp)%mod+(long long int)func(n-1,'u',dp)... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n int help(int i,int prev,vector<char> &vowels,int n, vector<vector<int>> &dp){\n if(i>=n) {\n return 1;\n }\n if(dp[i][prev+1]!=-1) return dp[i][prev+1];\n long long ans=0;\n for(int c=0;c<5;c++){\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "// Class to implement the Top-down approach:\nclass Solution {\n vector<char> vowels = {'a','e','i','o','u'};\n const int MOD = 1e9+7;\n\npublic:\n // Method to count how many such strings of length n that can be formed, using recursion with memoization - O(N) & O(N)\n int countVowelPermutation... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\n int mod=1e9+7 ;\nprivate:\n int count(const string &s, int i, int n, char prev, vector<vector<int>> &dp) {\n if (i == n) return 1; \n int prev_index = abs(prev-'a') ;\n \n if (dp[i][prev_index] != -1) return dp[i][prev_index]%mod;\n \n int ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(int i, char flag, int n, vector<vector<int>>& dp){\n if(i==n) return 1;\n int mod=1000000007;\n if(flag=='0'){\n int ans=0;\n vector<char> vowels{'a','e','i','o','u'};\n for(int j=0;j<5;j++){\n a... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7, n;\n vector<vector<int>> memo;\n unordered_map<char, vector<char>> m = {{'#', {'a', 'e', 'i', 'o', 'u'}}, {'a', {'e'}}, {'e', {'a', 'i'}}, {'i', {'a', 'e','o', 'u'}}, {'o', {'i', 'u'}}, {'u', {'a'}}};\n int countVowelPermutation(int n) {\n thi... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<char,string>mp;\n int mod = 1e9+7;\n vector<vector<int>>dp;\n int solve(int ind, char ch,int n){\n if(ind>=n) return 1;\n if(dp[ind][ch-'a'] != -1) return dp[ind][ch-'a'];\n long long ans=0;\n for(auto it:mp[ch]){\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1000000007;\n int getStrCount(vector<vector<int>> &dp, int pos, char ch, int n, unordered_map<char, vector<char>> &vowelMap){\n if(pos == n)return 1;\n int charIdx = ch -'a';\n if(dp[pos][charIdx] != -1)return dp[pos][charIdx];\n\n dp... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<char, vector<char>>mp{\n {'a',{'e'}}, \n {'e', {'a','i'}},\n {'i', {'a','e','o','u'}},\n {'o', {'i', 'u'}},\n {'u',{'a'}}\n };\n vector<vector<int>>memo;\n int MOD = 1e9+7;\n int dp(int n, char cur){\n if(n==... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "#define mod 1000000007\nclass Solution {\npublic:\n int solve(char curr,int len,unordered_map<char,vector<char>>&mp,vector<vector<int>>&dp){\n if(len==0) return 1;\n if(dp[len][curr-'a']!=-1) return dp[len][curr-'a'];\n int cnt=0;\n for(auto x:mp[curr]){\n cnt=(cnt... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int m=1000000007;\n int dfs(int n,char prev, unordered_map<char,vector<char>>& allowed,vector<vector<int>>& dp)\n {\n if(n==0)\n return 1;\n if(n<0)\n return 0;\n if(dp[n][prev-'a']==-1)\n {\n int ans=0;\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\n const int mod = 1e9 + 7;\n int solve(char ch, int n, map<char, vector<char>> &mp, vector<vector<int>> &dp) {\n if(n == 0) {\n return 1;\n }\n \n if(dp[n][ch - 'a'] != -1) return dp[n][ch - 'a'];\n \n int ans = 0;\n for(cha... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int addMod(int a, int b) { return (a % mod + b % mod) % mod; }\n int countWow(vector<vector<int>>& dp, map<char, vector<char>>& mp, int n,\n char prv) {\n if (n == 0) {\n return 1;\n }\n\n if (dp[n][pr... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<long>> memo;\n\n int countVowelPermutation(int n) {\n unordered_map<char, vector<char>> adj;\n memo.resize(26, vector<long>(n + 1, -1));\n \n\n adj['a'].push_back('e');\n adj['e'].push_back('a');\n adj['e'].push_back(... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<long long>> memo(26, vector<long long>(n, 0));\n\n unordered_map<char, string> dict;\n dict['a'] = \"e\";\n dict['e'] = \"ai\";\n dict['i'] = \"aeou\";\n dict['o'] = \"iu\";\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<char, int> idxMap;\n int countVowelPermutation(int n) {\n vector<vector<long long>> memo(26, vector<long long>(n, 0));\n\n unordered_map<char, string> dict;\n dict['a'] = \"e\";\n dict['e'] = \"ai\";\n dict['i'] = \"aeou\";\... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "\nint mod=1e9+7;\nint solve(int i,int mask,vector<vector<int>>&dp)\n{\n if(i==dp.size()-10)\n return 1;\n if(dp[i][mask]!=-1)return dp[i][mask];\n long long ways=0;\n for(int j=0;j<5;j++)\n {\n if(((mask>>j)&1))\n {\n \n if(j==0)\n {\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution1 {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<long>> dp(n, vector<long>(5,0));\n const int MOD7 = 1e9+7;\n\n for(int i = 0; i < n; i++)\n {\n if (i == 0)\n {\n for(int j = 0; j < 5; j++)\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "#define mod 1000000007\nclass Solution {\npublic:\n // int f(int i, int last, int n, unordered_map<int, vector<int>>& mp, vector<vector<int>>& dp) {\n // if (i == n) return 1;\n // if (dp[i][last] != -1) return dp[i][last];\n // vector<int> nexts = mp[last];\n // long long wa... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n vector<vector<long long>>dp(n,vector<long long>(26,0));\n dp[n-1][0]=1;\n dp[n-1][4]=1;\n dp[n-1][8]=1;\n dp[n-1][14]=1;\n dp[n-1][20]=1;\n long long mod=1e9+7;\n for(int i=n-2;i>=0;-... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n\n int countVowelPermutation(int n) {\n vector<vector<long long>> dp(n+1,vector<long long>(26,1));\n string vowel = \"aeiou\";\n for(int i = 2;i <= n;i++){\n for(char j : vowel){\n int x = j - 'a';\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n long long mod=1e9+7;\n long long f(int n,int prev,vector<vector<long long>>& dp){\n \n if(n==0){\n return 1;\n }\n \n if(dp[n][prev+1]!=-1){\n return dp[n][prev+1];\n }\n \n if(prev==-1){\n ... |
1,332 | <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p>
<ul>
<li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'... | 3 | {
"code": "class Solution {\npublic:\n\nlong long mod =1e9+7;\nlong long f(int i,char prev,int n,vector<vector<long long >>&dp)\n{\n if(i>=n)\n return 1;\n\n if(dp[i][prev-'a']!=-1)\n return dp[i][prev-'a'];\n\n\n if(prev=='a')\n return dp[i][prev-'a']=f(i+1,'e',n,dp)%mod;\n\n else if(prev=='e'... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nstatic const int __ = [](){... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nstatic const int __ = [](){... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "/**\n * Definition for singly-linked list.\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 */\n\n static const int __ = []... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "/**\n * Definition for singly-linked list.\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 */\n\nstatic const int __ = [](... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "/**\n * Definition for singly-linked list.\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 */\n\nstatic const int __ = [](... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "class Solution {\npublic:\n ListNode* swapNodes(ListNode* head, int k) { return solve2(head, k); }\n\n // swap values\n ListNode* solve1(ListNode* head, int k) {\n ListNode* p = head;\n while (--k > 0) { p = p->next; }\n ListNode *p1 = p, *p2 = head;\n while (p->next) {\n p = p->next;\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 0 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nclass Solution {\npublic:\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 1 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nclass Solution {\npublic:\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 1 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nclass Solution {\npublic:\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 2 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nclass Solution {\npublic:\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 2 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nstatic const int __ = [](){... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nclass Solution {\npublic:\n... |
528 | <p>You are given the <code>head</code> of a linked list, and an integer <code>k</code>.</p>
<p>Return <em>the head of the linked list after <strong>swapping</strong> the values of the </em><code>k<sup>th</sup></code> <em>node from the beginning and the </em><code>k<sup>th</sup></code> <em>node from the end (the list i... | 3 | {
"code": "/**\n * Definition for singly-linked list.\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 */\nclass Solution {\npublic:\n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.