id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\n // int solve( vector<int>& coins , int amount , int sum , int index){\n // if(index == coins.size()){\n // if(sum == amount) return 1;\n // else return 0;\n // }\n // int includeCoin = solve(coins, amount, sum + coins[index], index);\n //...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "int DP[301][15001];\n\nint func(int idx,int amount,vector<int>& coins){\n if(amount==0)return 1;\n if(idx<0)return 0;\n\n if(DP[idx][amount]!=-1)return DP[idx][amount];\n\n int ways=0;\n for(int coinamount=0;coinamount<=amount;coinamount+=coins[idx]){\n ways+=func(idx-1,amount-coinam...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "\nclass Solution {\npublic:\n int dp[400][10001];\n int solve(int i, int amount, vector<int>& coins) {\n if (amount < 0 || i >= coins.size()) return 0;\n if (amount == 0) return 1;\n if (dp[i][amount] != -1) return dp[i][amount];\n if (amount >= coins[i]) {\n re...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int dp[302][5002];\n int solvememo(int amount,vector<int>&arr,int idx){\n if(idx==arr.size()){\n if(amount==0) return 1;\n return 0;\n }\n if(dp[idx][amount]!=-1) return dp[idx][amount];\n int take = 0;\n int nottake...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "// e.g:- 1,1,1,2 and 2,1,1,1 are same {that's why we don't use for loop}\n\n//Approach-1 (Recursion + Mempozation) : O(n*amount)\nclass Solution {\npublic:\n int n;\n int t[301][5001];\n \n\n // int solve(int i, vector<int>& coins, int amount) {\n \n // if(amount == 0)\n // ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "//Approch 1\nclass Solution {\npublic:\n /*this code find ways and its combination in ques we have to not find combination*/\n int solve(vector<int>&arr,int target,vector<int> path) {\n int n=arr.size();\n if(target==0) {\n for(auto &x:path) {\n cout<<x<<\" \";...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "// e.g:- 1,1,1,2 and 2,1,1,1 are same {that's why we don't use for loop}\n\n//Approach-1 (Recursion + Mempozation) : O(n*amount)\nclass Solution {\npublic:\n int n;\n int t[301][5001];\n \n\n // int solve(int i, vector<int>& coins, int amount) {\n \n // if(amount == 0)\n // ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "\n class MyHash\n{\npublic:\n size_t operator () (const pair<int, int>& tuple) const\n {\n return hash<int>()(tuple.first) ^ hash<int>()(tuple.second);\n }\n};\n\nclass Solution {\n vector<vector<int>> tab;\n vector<int> tab_cc;\n\npublic:\n \n int changeCoins (vector<int>& coins, int n, ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "\n class MyHash\n{\npublic:\n size_t operator () (const pair<int, int>& tuple) const\n {\n return hash<int>()(tuple.first) ^ hash<int>()(tuple.second);\n }\n};\n\nclass Solution {\n vector<vector<int>> tab;\n vector<int> tab_cc;\n\npublic:\n \n int changeCoins (vector<int>& coins, int n, ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int solve(int idx, int target, vector<int>& coins){\n if(idx==0){\n if(target%coins[idx]==0)\n return 1;\n return 0;\n }\n if(dp[idx][target]!=-1)\n return dp[idx][target];\n ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int solve(vector<int>& coins,int amount,int i,vector<vector<int>>& dp){\n if(i<0)return 0;\n if(amount==0)return 1;\n if(dp[i][amount]!=-1)return dp[i][amount];\n int notake=solve(coins,amount,i-1,dp);\n int take=0;\n if(amount>=coins...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int coin(int i, vector<int> &coins, int amount, int curr,vector<vector<int>> &dp) {\n if (i >= coins.size()) {\n return curr == amount ? 1 : 0;\n }\n if (curr > amount) {\n return 0;\n }\n if(dp[i][curr]!=-1){\n ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int change(int amount, vector<int>& coins) {\n int n = coins.size(), i, j;\n vector<vector<int>> dp(n+1, vector<int>(5001,0));\n for(i=0; i<=n; i++){\n dp[i][0] = 1;\n }\n \n // rec relation is -> include atleast one of co...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int change(int amount, vector<int>& coins) {\n int n = coins.size(), i, j;\n vector<vector<int>> dp(n+1, vector<int>(5001,0));\n for(i=0; i<=n; i++){\n dp[i][0] = 1;\n }\n \n // rec relation is -> include atleast one of co...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int solve(vector<int>& coins,int i,int x)\n {\n if(x==0) return 1;\n if(i>=coins.size() || x<0) return 0;\n if(dp[i][x]!=-1) return dp[i][x];\n return dp[i][x] = solve(coins,i,x-coins[i])+solve(coins,i+1,x);\n ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n\n int f(int amt, vector<int>& c, int ind, int sum, vector<vector<int>>& dp) {\n if (sum==amt) {\n return 1;\n }\n if (sum > amt) return 0;\n if (ind < 0) {\n return (sum==amt);\n }\n if (dp[ind][sum] != -1) retur...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int solve(int ind, int currsum, vector<int>& coins, int amount, vector<vector<int>>& dp) {\n if(currsum > amount) return 0;\n if(currsum == amount) return 1;\n if(ind == coins.size()) return 0;\n if(dp[ind][currsum] != -1) return dp[ind][currsum];\...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n\tint change(int amount, const vector<int>& coins) {\n\t\tif ((amount == 0) && (!coins.empty()))\n\t\t\treturn 1;\n\n\t\tauto sortedCoins = coins;\n\t\tstd::sort(sortedCoins.begin(), sortedCoins.end(), std::greater<int>());\n\t\treturn changeImpl(amount, sortedCoins, 0);\n\t}\n\n...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\nunordered_map<int ,unordered_map<int,int>>memo;\n int f(int ind,int target, vector<int>&coins){\n if(ind==0) return (target % coins[0]==0);\n if(memo[ind].find(target)!=memo[ind].end()) return memo[ind][target];\n int not_take=f(ind-1,target,coins);\n ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\nunordered_map<int ,unordered_map<int,int>>memo;\n int f(int ind,int target, vector<int>&coins){\n if(ind==0) return (target % coins[0]==0);\n if(memo[ind].find(target)!=memo[ind].end()) return memo[ind][target];\n int not_take=f(ind-1,target,coins);\n ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n \n int dp[301][5001];\n int solve(int amount,int idx,vector<int>&coins){\n \n if(amount==0)return 1;\n if(dp[idx][amount]!=-1)return dp[idx][amount];\n int count=0;\n for(int i=idx;i<coins.size();i++){\n if(amount>=coins[i])...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int dp[5001][301];\n int help(int amt, int idx, vector<int>& nums) {\n if (amt == 0)\n return 1;\n if (idx >= nums.size())\n return 0;\n if (dp[amt][idx] != -1)\n return dp[amt][idx];\n int take = 0;\n if ...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int change(int amount, vector<int>& coins) {\n int n = coins.size() ;\n vector<long> prev(amount+1,0) ; // prev[T] = Number of ways of forming amount T using coins upto previous index (initially 0)\n\n // BASE CASE : If only one coin is left to choose fro...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int change(int T, vector<int>& arr) {\n int n=arr.size();\n \n vector<long> prev(T + 1, 0); // Create a vector to store the previous DP state\n\n // Initialize base condition\n for (int i = 0; i <= T; i++) {\n if (i % arr[0] == 0...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\n int countWaysToMakeChangeUtil(vector<int>& arr, int ind, int T, vector<vector<int>>& dp) {\n // Base case: if we're at the first element\n if (ind == 0) {\n // Check if the target sum is divisible by the first element\n return (T % arr[0] == 0);\n }\n \n /...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n int change(int amount, vector<int>& coins) {\n vector<long> prev(amount+1,0); \n for (int i=0;i<=amount;i++){\n if (i%coins[0]==0)\n prev[i]=1; \n }\n\n for (int ind = 1; ind < coins.size(); ind++) {\n vector<long> cur(amount + 1, 0); \n...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\n int countWaysToMakeChangeUtil(vector<int>& arr, int ind, int T, vector<vector<int>>& dp) {\n // Base case: if we're at the first element\n if (ind == 0) {\n // Check if the target sum is divisible by the first element\n return (T % arr[0] == 0);\n }\n \n /...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\nprivate:\n int count_ways(int idx, int target, vector<vector<int>>& dp, vector<int>& coins){\n if(idx == 0){\n if(target % coins[idx] == 0){\n return 1;\n }\n else{\n return 0;\n }\n }\n if(d...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic:\n\n\n// Function to count the number of ways to make change for a given target sum\nlong countWaysToMakeChangeUtil(vector<int>& arr, int ind, int T, vector<vector<long>>& dp) {\n // Base case: if we're at the first element\n if (ind == 0) {\n if(T%arr[0]==0) return 1;...
518
<p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p> <p>Return <em>the number of combinations that make up that amount</em>. If that amount of money cannot be made up by any combination of the coi...
3
{ "code": "class Solution {\npublic: long countWaysToMakeChangeUtil(vector<int>& arr, int ind, int T, vector<vector<long>>& dp) {\n // Base case: if we're at the first element\n if (ind == 0) {\n // Check if the target sum is divisible by the first element\n return (T % arr[0] == 0);\n }\n ...
903
<p>Given the <strong>API</strong> <code>rand7()</code> that generates a uniform random integer in the range <code>[1, 7]</code>, write a function <code>rand10()</code> that generates a uniform random integer in the range <code>[1, 10]</code>. You can only call the API <code>rand7()</code>, and you shouldn&#39;t call an...
0
{ "code": "// The rand7() API is already defined for you.\n// int rand7();\n// @return a random integer in the range 1 to 7\n\nclass Solution {\n public:\n int rand10() {\n int num = 40;\n\n while (num >= 40)\n num = (rand7() - 1) * 7 + rand7() - 1;\n\n return num % 10 + 1;\n }\n};", "memory": "9800...
903
<p>Given the <strong>API</strong> <code>rand7()</code> that generates a uniform random integer in the range <code>[1, 7]</code>, write a function <code>rand10()</code> that generates a uniform random integer in the range <code>[1, 10]</code>. You can only call the API <code>rand7()</code>, and you shouldn&#39;t call an...
0
{ "code": "// The rand7() API is already defined for you.\n// int rand7();\n// @return a random integer in the range 1 to 7\n\nclass Solution {\npublic:\n int rand10() {\n int ans=INT_MAX;\n while(ans>=40){\n ans=7*(rand7()-1)+rand7()-1;\n }\n return ans%10+1;\n\n }\n};", "memor...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
0
{ "code": "class Solution {\npublic:\n unordered_set<string> dict;\n unordered_map<string, bool> m;\n vector<int> dp;\n int n;\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n n = words.size();\n for(string w: words){\n dict.insert(w);\n }\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
0
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> result;\n unordered_set<string_view> wordList;\n for (auto& word : words) wordList.insert(string_view(word));\n\n for (auto& word : words) {\n vecto...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
0
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> ans;\n\n unordered_set<string> s(words.begin(),words.end());\n int n = words.size();\n\n for(int k = 0; k < n; k++){\n int length = words[k].size();...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
0
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> ans;\n\n unordered_set<string> s(words.begin(),words.end());\n int n = words.size();\n\n for(int k = 0; k < n; k++){\n int length = words[k].size();...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
0
{ "code": "class Solution {\npublic:\n unordered_set<string> st;\n bool check(int ind, string &s , vector<int> &dp){\n \n int n = s.size();\n if(ind == n) return 1;\n\n if(dp[ind]!=-1) return dp[ind];\n string temp =\"\";\n bool a= false;\n //i 0 hoga to n-2 pe r...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
0
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\nmap<string, int> mp;\n for (const string& s : words) {\n mp[s]++;\n }\n vector<string> ans;\n for ( auto & s : words) {\n int n = s.length();\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
1
{ "code": "class Solution {\npublic:\n bool check(unordered_set<string> &s, string word){\n int n = word.size();\n vector<int> dp(n+1,0);\n dp[0]=1;\n for (int i=1;i<=n;i++){\n for (int j=0;j<i;j++){\n if (dp[j] && (s.count(word.substr(j,i-j))) && (j>0 || i<n))...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
1
{ "code": "class Solution {\npublic:\n struct CompareLength {\n inline bool operator() (const string& l, const string& r) {\n return l.length() < r.length();\n }\n };\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n int n = words.size();\n sor...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
1
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> wordSet(words.begin(), words.end());\n vector<string> concatenatedWords;\n \n for (const string& word : words) {\n wordSet.erase(word); // Te...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
1
{ "code": "class Solution {\npublic:\n bool canForm(const string& word, unordered_set<string>& wordSet) {\n int n = word.size();\n vector<bool> dp(n + 1, false);\n dp[0] = true;\n\n for (int i = 1; i <= n; ++i) {\n for (int j = 0; j < i; ++j) {\n if (dp[j] && w...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
1
{ "code": "class Solution {\npublic:\n bool solve(string &s,unordered_set<string>& st,int i,vector<int>&dp){\n\n if(i == s.length())\n return true ;\n\n if(dp[i] != -1)\n return dp[i];\n\n for(int j=i; j<s.length(); j++){\n string temp = s.substr(i,j-i+1);\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
1
{ "code": "class Solution {\nprivate:\n\n // normal word break - 1\n // this helper will run for average O(N^2)\n // iterative\n bool wordBreak(string s, unordered_set<string> &st,\n vector<int> &dp) {\n int n = s.size();\n dp[n]=1;\n for(int i=n-1;i>=0;i--){\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> dict(words.begin(), words.end());\n vector<string> ans;\n for(string word : words) {\n dict.erase(word);\n vector<int> dp(word.size(), -1...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n unordered_map<string,int>mp;\n bool solve(int ind, string str,vector<int>& dp){\n if(ind == str.size()) return true;\n if(dp[ind] != -1) return dp[ind];\n\n string temp = \"\";\n bool ans = false;\n\n for(int i = ind;i<str.size();i++){\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\nprivate:\n set<string> st;\n int n;\n int solve(int ind, string s, vector<int> &dp) {\n if(ind >= n)\n return 1;\n\n if(dp[ind] != -1)\n return dp[ind];\n\n string temp = \"\";\n for(int i=ind; i<n; i++) {\n temp += s[i...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n\n bool checkInList(string &s, int i, unordered_map<string, int> &mp, vector<int> &dp){\n if(i>=s.length()){\n return true;\n }\n if(dp[i]!=-1) return dp[i];\n string str=\"\";\n for(int j=i ; j<s.length() ; j++){\n str+...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> mp;\n\n bool find(string s, unordered_set<string>& st) {\n\n if (mp.count(s))\n return mp[s];\n\n string current = \"\";\n\n for (int i = 0; i < s.size(); i++) {\n current += s[i];\n\n if (st...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> memo;\n\n bool helper(string& s, unordered_set<string>& st, int start) {\n if (start >= s.size()) return false;\n if (memo.find(s.substr(start)) != memo.end()) return memo[s.substr(start)];\n\n string current = \"\";\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\n map<pair<string,int>,bool> dp;\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> ans;\n unordered_set<string> s(words.begin(),words.end());\n\n for(auto &w : words){\n string temp = w;\n s....
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\n map<pair<string,int>,bool> dp;\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> ans;\n unordered_set<string> s(words.begin(),words.end());\n\n for(auto &w : words){\n string temp = w;\n s....
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "#include <vector>\n#include <unordered_map>\n#include <string>\n\nusing namespace std;\n\nclass Solution {\npublic:\n bool isConcatenated(string str, unordered_map<string, bool>& wordMap, unordered_map<string, bool>& memo) {\n if (memo.count(str)) return memo[str];\n if (str.empty()) retur...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n vector<string> finalAns;\n\n bool check(string s, set<string>& st, map<string,bool>& dp)\n {\n if(s.size() == 0)return true;\n if(dp.find(s) != dp.end())return dp[s];\n\n bool ans = false;\n for(int i = 0; i < s.size(); i++)\n {\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n bool helper(string s,int i,map<string,int>&h,map<string,int>&ans,map<string,int>&cuts){\n if(ans.count(s.substr(i))){\n return ans[s.substr(i)];\n }\n for(int j=i;j<s.size();j++){\n string s1=s.substr(i,j-i+1) ;\n if(h.cou...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n bool helper(string s,int i,map<string,int>&h,map<string,int>&ans,map<string,int>&cuts){\n if(ans.count(s.substr(i))){\n return ans[s.substr(i)];\n }\n for(int j=i;j<s.size();j++){\n string s1=s.substr(i,j-i+1) ;\n if(h.cou...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n bool check(string a, int idx, set<string> &st, string ignore, unordered_map<string, bool> &memo) {\n if (idx == a.size()) {\n return true;\n }\n \n string key = a.substr(idx);\n if (memo.find(key) != memo.end()) {\n ret...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n struct TrieNode {\n char c = '\\0';\n bool isEnd = false;\n };\n vector<TrieNode> nodes;\n vector<vector<size_t>> edges;\n\n nodes.push_back(Trie...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n struct TrieNode {\n char c = '\\0';\n bool isEnd = false;\n };\n vector<TrieNode> nodes;\n vector<vector<size_t>> edges;\n\n nodes.push_back(Trie...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n int dp[31][3];\n bool fn (string& s, map<string, int>& ht, int i, int cnt) {\n if (i == s.size()) {\n if (cnt == 2) return dp[i][cnt] = true;\n return dp[i][cnt] = false;\n }\n if (dp[i][cnt] != -1) return dp[i][cnt];\n\n s...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\nvector<string> ans;\nint dp[31][31];\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n map<string,int> mp;\n for(auto it:words){\n mp[it]++;\n }\n for(int i=0;i<words.size();i++){\n if(!words[i].empty()){\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> mp;\n vector<string> final_ans;\n int dp[10010]; \n\n bool back(int pos, string& s){\n if(pos == s.length()) return true;\n if(dp[pos] != -1) return dp[pos];\n \n string currentWord = \"\";\n for(int i = ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n static int compare(string& a, string& b) {\n return a.size() < b.size();\n }\n bool solve(string s, map<string,bool>& dict) {\n if (dict.find(s) != dict.end())\n {\n if (dict[s])\n return true;\n else\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n\n int dp[32];\n\n int f(int idx,string&s,unordered_map<string,int>&m){\n if(idx==s.length())return 1;\n if(dp[idx]!=-1)return dp[idx];\n string temp=\"\";\n int ans=0;\n for(int i=idx;i<s.length();i++){\n temp.push_back(s[i]);\...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n unordered_map<string,bool> mp ;\n int dp[35] ;\n\n bool help(int i, string &word ){\n int n = word.size() ; \n if(i==n) return true;\n\n if(dp[i] != -1) return dp[i] ;\n\n bool is = false ;\n string s = \"\" ;\n for(int j = i ; ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\nunordered_map<string,int>mp;\nint dp[31];\n bool conc(string &word,int i)\n {\n int n=word.size();\n if(i==n)\n return true;\n if(dp[i]!=-1)\n return dp[i];\n bool a=false;\n for(int j=1;j<=min(n-1,n-i);j++)//j is length of string fro...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n int help(int ind, string& s, map<string,int>& mp, vector<int>& dp) {\n if(ind == s.size()) {\n return 1;\n }\n if(dp[ind] != -1) {\n return dp[ind];\n }\n string tmp = \"\";\n for(int k=ind; k<s.size(); k++) {\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "#include <unordered_map>\n\nclass Solution {\npublic:\n \n map<string, bool> memo;\n\n bool solve(string& target, string& temp, vector<vector<string>>& adj) {\n if (temp.length() == target.length()) {\n return temp == target;\n }\n \n if (temp.length() > targ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n bool check(string &s,int idx,vector<int>&dp,unordered_map<string,int>&mp){\n if(idx>=s.size())return 1;\n if(dp[idx]!=-1)return dp[idx];\n string temp=\"\";\n bool ans=0;\n for(int j=idx;j<s.size();j++){\n if(idx==0 and j==s.size(...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\n #define pb push_back\n int dp[35][35][4];\n bool func(int index,int last, int cnt , string temp, string& s1, map<string,int>& mp){\n if(index == s1.size()){\n if(temp.size()==0 && cnt==2) return true;\n else return false;\n }\n if( dp[i...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> ans;\n for(auto& word: words)\n {\n reverse(word.begin(), word.end());\n }\n sort(words.begin(), words.end(), [&](string& lhs, string& rhs) -...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n bool dfs(const string& word, int length, vector<bool>& visited, const unordered_set<string>& dictionary) {\n if(length == word.size()) {\n return true;\n }\n if(visited[length]) {\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n bool backtracking(const string& word, unordered_set<string>& words_set, vector<bool>& visited, int index) {\n if (index == word.size()) return true;\n visited[index] = true;\n for (int i = word.size() - (index == 0 ? 1 : 0); i >= index; --i) {\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic: \n unordered_map<string,bool> m;\n bool dpf(string & w, vector<string>& words, unordered_map<string,int>&mp){\n if(m.count(w)) return m[w];\n int n=w.size();\n for(int i=1;i<n;i++){\n string p=w.substr(0,i);\n string s=w.substr(i);\...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n unordered_map<string, bool>um;\n unordered_map<string, bool>dp;\n bool helper(string &s) {\n if(s.length() == 0) return true;\n if(dp.count(s)) return dp[s];\n for(int i=1; i<s.length(); i++) {\n string p1 = s.substr(0, i);\n s...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n map<string,int> mp;\n vector<vector<int>> dp;\n string s; \n int rec(int l,int r){\n if(dp[l][r] != -1 ) return dp[l][r];\n \n string temp = s.substr(l,r-l+1);\n \n if(mp.find(temp)!= mp.end() and mp[temp] == 1){\n \n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
2
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> words_set;\n for (string word : words) words_set.insert(word);\n vector<string> res;\n \n for (string word : words) {\n int n = word.size(...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n bool func(int i,string& s,map<string,int>& mp,vector<int>& dp){\n int n = s.size();\n if(i>=n)return 0;\n if(i>0 && mp[s.substr(i)])return 1;\n if(dp[i]!=-1)return dp[i];\n bool ans = 0;\n for(int j=1;i+j<n;j++){\n if(mp[s....
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\n map<pair<string,int>,bool>mpp2;\n unordered_map<string,int>mpp;\n bool solve(string s, int i)\n {\n if(i>=s.length())return true;\n if(mpp2.find({s,i})!=mpp2.end())return mpp2[{s,i}];\n for(int j=i+1;j<s.length()+1;++j)\n {\n string s2=s.s...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n int rec(int i,int j,string s,string temp,unordered_map<string,int> &mp,vector<vector<int>> &dp)\n {\n int n=s.size();\n temp+=s[i];\n\n if(dp[i][j]!=-1)\n return dp[i][j];\n\n if(i==n-1)\n {\n if(mp[temp])\n r...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n int rec(int i,int j,string s,string temp,unordered_map<string,int> &mp,vector<vector<int>> &dp)\n {\n int n=s.size();\n temp+=s[i];\n\n if(dp[i][j]!=-1)\n return dp[i][j];\n\n if(i==n-1)\n {\n if(mp[temp])\n r...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> dictionary(words.begin(), words.end());\n vector<string> answer;\n for (const string& word : words) {\n const int length = word.length();\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n unordered_map<string,int> mp;\n\n bool solve(int ind, string &s, int n, vector<int> &dp){\n if(ind == n) return true;\n\n if(dp[ind] != -1) return dp[ind];\n\n string temp = \"\";\n\n for(int k=ind;k<n;k++){\n temp += s[k];\n\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class TrieNode {\npublic:\n vector<TrieNode*> children;\n int path = 0;\n int end = 0;\n\n TrieNode(){\n children.assign(26,nullptr);\n }\n};\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n return byBfs(words);\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class TrieNode {\npublic:\n vector<TrieNode*> children;\n int path = 0;\n int end = 0;\n\n TrieNode(){\n children.assign(26,nullptr);\n }\n};\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n return byBfs(words);\n }\...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "struct Trie{\n map <char, Trie*> next;\n bool end = false;\n};\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n Trie* root = new Trie;\n for(string word: words){\n Trie* curr = root;\n for(char ch: word){\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n const int p = 31;\n const int mod = 1e9 + 9;\n long long pwr[31];\n long long inv[31];\n long long mexp(int a, int b) {\n long long res = 1;\n while (b>0) {\n if(b&1) res = (res*a)%mod;\n a = (1LL*a*a)%mod;\n b = b>>1...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n\n bool check(int start, int end, string &s,vector<vector<int>> &dp,unordered_set<string> &dict){\n if(end == s.size()){\n return start == end;\n }\n if(dp[start][end] != -1)\n return dp[start][end];\n \n // take end\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n\n bool check(int start, int end, string &s, vector<string> &curPos,vector<vector<int>> &dp,unordered_set<string> &dict){\n if(end == s.size()){\n return start == end;\n }\n if(dp[start][end] != -1)\n return dp[start][end];\n \...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> s;\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> res;\n for(string& w:words)\n s.insert(w);\n for(string& w:words)\n {\n vector<vector<int>> dp(w.size()+1,vec...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\nvector<string> ans;\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> st(words.begin(),words.end());\n vector<vector<int>> dp;\n for(int i=0;i<words.size();i++){\n if(!words[i].empty()){\n dp=...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\nvector<string> ans;\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> st(words.begin(),words.end());\n vector<vector<int>> dp;\n for(int i=0;i<words.size();i++){\n if(!words[i].empty()){\n dp=...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> s;\n bool check(string& word,int index,int cnt,vector<vector<int>>&dp){\n if(index==word.size()){\n if(cnt>=2) return true;\n return false;\n }\n if(dp[index][cnt]!=-1){\n return dp[index][cnt];\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n set<string> word;\n for(auto i:words) word.insert(i);\n vector<string> ans;\n for(auto x:words){\n cout<<\"curr word:\"<<x<<\"\\n\";\n word.erase(x);\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n \n bool checkConcatenation(int currIndex, int lastIndex, int sz, string &s, set<string> &st, vector<vector<int>> &dp){\n if(currIndex==sz-1){\n if(lastIndex==0) return 0;\n string str=s.substr(lastIndex,currIndex-lastIndex+1);\n if(st...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n\n int f(string &curr,unordered_set<string> &data,vector<vector<int>> &dp,int ind,int pre,string match)\n {\n if(ind==curr.size())\n {\n if(data.find(match)!=data.end() && match!=curr)\n return 1;\n return 0;\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n #define vi vector<int>\n #define vvi vector<vi>\n #define pb push_back\n #define dbg(x) cout << #x << \" : \" << x << endl\n\n int node_cnt = 1;\n int cnt[300005];\n int ends[300005];\n void add(string &s , vvi &trie){\n int x = 0;\n for(int...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, int> mp;\n bool CheckSubstring(vector<string>& dictionary, string sentence,\n int curIndex, int lastIndex, vector<vector<int>>& dp) {\n if (curIndex == sentence.length() - 1) {\n if(lastIndex==0) return 0;\n ...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Trie{\npublic:\n int flag;\n unordered_map<char, Trie*>child;\n Trie(){\n flag = -1;\n }\n};\nclass Solution {\npublic:\n static bool vec_sort(string& a, string& b){\n return a.length() < b.length();\n }\n void go(Trie* node, Trie* root, string& s, int spot, vector<...
472
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p> <p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne...
3
{ "code": "class Trie{\npublic:\n int flag;\n unordered_map<char, Trie*>child;\n Trie(){\n flag = -1;\n }\n};\nclass Solution {\npublic:\n void go(Trie* node, Trie* root, string& s, int spot, vector<string>& ans, int depth){\n if(node->child.count(s[spot]) == 0){\n if(depth != ...