question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
concatenated-words | C++ || Simple DP (With Full Explanation) || Beats 99% 🏁🔥 | c-simple-dp-with-full-explanation-beats-cj40x | Intuition\nThe intuition behind this solution is to use dynamic programming to check if a word can be constructed by the concatenation of other words in the set | ufoblivr | NORMAL | 2023-01-27T01:29:10.761505+00:00 | 2023-01-27T02:22:37.663535+00:00 | 25,185 | false | # Intuition\nThe intuition behind this solution is to use dynamic programming to check if a word can be constructed by the concatenation of other words in the set.\n\n# Approach\nFirst, the input list of words is converted into an unordered_set, which is an efficient data structure for checking if a word is in the set ... | 537 | 1 | ['String', 'Dynamic Programming', 'Depth-First Search', 'C++'] | 15 |
concatenated-words | Java DP Solution | java-dp-solution-by-shawngao-h7fv | Do you still remember how did you solve this problem? https://leetcode.com/problems/word-break/\n\nIf you do know one optimized solution for above question is u | shawngao | NORMAL | 2016-12-18T05:35:57.320000+00:00 | 2018-10-20T22:49:26.044921+00:00 | 70,677 | false | Do you still remember how did you solve this problem? https://leetcode.com/problems/word-break/\n\nIf you do know one optimized solution for above question is using ```DP```, this problem is just one more step further. We iterate through each ```word``` and see if it can be formed by using other ```words```.\n\nOf cour... | 466 | 5 | [] | 60 |
concatenated-words | Python DFS readable solution | python-dfs-readable-solution-by-kv391p-1l3v | \nclass Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n """\n :type words: List[str]\n :rtype: List[str]\n | kv391p | NORMAL | 2018-08-13T02:39:02.659235+00:00 | 2018-09-01T14:39:40.220553+00:00 | 28,843 | false | ```\nclass Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n """\n :type words: List[str]\n :rtype: List[str]\n """\n d = set(words)\n \n def dfs(word):\n for i in range(1, len(word)):\n prefix = word[:i]\n ... | 412 | 12 | [] | 53 |
concatenated-words | Java Common template - Word Break I, Word Break II, Concatenated Words | java-common-template-word-break-i-word-b-590g | Word Break I - Link\n Word Break II - Link \n Concatenated Words - Link\n\nCommon approach for Word Break I, Word Break II, and Concatenated Words problems. \nC | bluesky299 | NORMAL | 2019-08-01T22:17:50.618360+00:00 | 2021-02-09T17:15:02.111962+00:00 | 20,591 | false | * Word Break I - [Link](https://leetcode.com/problems/word-break/)\n* Word Break II - [Link](https://leetcode.com/problems/word-break-ii/) \n* Concatenated Words - [Link](https://leetcode.com/problems/concatenated-words/)\n\nCommon approach for Word Break I, Word Break II, and Concatenated Words problems. \nConcatenate... | 247 | 1 | ['Dynamic Programming', 'Depth-First Search', 'Java'] | 16 |
concatenated-words | Day 27 || Simple Recursion - DFS || Easiest Beginner Friendly Sol | day-27-simple-recursion-dfs-easiest-begi-sm2n | Intuition of this Problem:\nWe can solve this problem using various methods:\n- Trie data strucutre\n- dynamic programming\n\nBut I solved this problem using si | singhabhinash | NORMAL | 2023-01-27T01:38:38.003349+00:00 | 2023-04-01T10:51:40.329638+00:00 | 9,329 | false | # Intuition of this Problem:\nWe can solve this problem using various methods:\n- Trie data strucutre\n- dynamic programming\n\nBut I solved this problem using simple recursion - dfs.\n {\n List<String> res = new ArrayList<String>();\n if (words == null || words | futurehau | NORMAL | 2017-01-12T02:32:27.881000+00:00 | 2018-08-28T22:42:24.104899+00:00 | 27,508 | false | ```\npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> res = new ArrayList<String>();\n if (words == null || words.length == 0) {\n return res;\n }\n TrieNode root = new TrieNode();\n for (String word : words) { // construct Trie tree\n ... | 129 | 5 | [] | 27 |
concatenated-words | Trie with Explanations | trie-with-explanations-by-gracemeng-tyhn | \nA concatenated word is a word add other word(words) as prefix.\n\nWe have to answer a question recursively: is a substring(word[x, word.length()-1]) prefixed | gracemeng | NORMAL | 2018-10-02T16:23:22.658797+00:00 | 2020-03-31T17:00:36.942007+00:00 | 14,464 | false | ```\nA concatenated word is a word add other word(words) as prefix.\n\nWe have to answer a question recursively: is a substring(word[x, word.length()-1]) prefixed with another word in words?\n\nThat\'s natural to prefix tree(trie). \n\nWe can build a trie using words and search for concatenated words in the trie. \n\nW... | 117 | 4 | [] | 18 |
concatenated-words | Python Template - Word Break I, Word Break II, Concatenated Words | python-template-word-break-i-word-break-35hco | Code & Idea for questions :\n1. Word Break : Ques No. 139\n2. Word Break II : Ques No. 140\n3. Concatenated Words : Ques No. 472\n\nBasic idea is same for all, | aayuskh | NORMAL | 2020-09-08T19:36:15.555035+00:00 | 2020-09-08T19:36:15.555087+00:00 | 8,330 | false | Code & Idea for questions :\n1. [Word Break : Ques No. 139](http://leetcode.com/problems/word-break/)\n2. [Word Break II : Ques No. 140](http://leetcode.com/problems/word-break-ii/)\n3. [Concatenated Words : Ques No. 472](http://leetcode.com/problems/concatenated-words/)\n\nBasic idea is same for all, find if string ca... | 102 | 0 | ['Dynamic Programming', 'Depth-First Search', 'Python'] | 10 |
concatenated-words | [Java] DFS + Memoization - Clean code | java-dfs-memoization-clean-code-by-hiepi-z09o | Solution 1: Straigtforward DFS + Memoization\njava\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<St | hiepit | NORMAL | 2020-03-16T15:07:55.260629+00:00 | 2020-03-17T16:00:29.580904+00:00 | 8,630 | false | **Solution 1: Straigtforward DFS + Memoization**\n```java\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> ans = new ArrayList<>();\n HashSet<String> wordSet = new HashSet<>(Arrays.asList(words));\n HashMap<String, Boolean> cache = new Hash... | 98 | 2 | [] | 14 |
concatenated-words | ✅C++💯💯image detailed explanation ✅✅ recursion | cimage-detailed-explanation-recursion-by-f7rz | \n\n\n\nNOTE:-here emoji says that ""ca","t" and "dogcats" all are present in set and returning true. if some part like tdogcats did not returened true as it wa | sonal91022 | NORMAL | 2023-01-27T06:02:42.850459+00:00 | 2023-05-12T05:41:07.713177+00:00 | 2,948 | false | \n\n C++ solution using DP and Trie | accepted-192ms-c-solution-using-dp-and-t-d2z2 | Following is pretty straight-forward, kind-of brute-force approach that result to TLE upon submission. Almost all the solution-posts follow this approach and re | mango_pickle | NORMAL | 2021-08-13T13:22:55.530879+00:00 | 2021-08-19T05:17:59.650069+00:00 | 4,335 | false | Following is pretty straight-forward, kind-of brute-force approach that result to TLE upon submission. Almost all the solution-posts follow this approach and result to TLE with newly added test-cases. \n```\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n ... | 37 | 1 | ['Dynamic Programming', 'Trie', 'C'] | 4 |
concatenated-words | C++ 772 ms dp solution | c-772-ms-dp-solution-by-hcisly-phwk | For any qualified word, there must be at least 3 indexes (at least 1 besides 0 and n-1 which n is the length of the word), which can be used to split the whole | hcisly | NORMAL | 2016-12-20T04:37:45.828000+00:00 | 2016-12-20T04:37:45.828000+00:00 | 10,236 | false | For any qualified word, there must be at least 3 indexes (at least 1 besides 0 and n-1 which n is the length of the word), which can be used to split the whole string to at least two sub strings and all sub strings can be found in words.\nE.g. input ```["cat","cats", "dog", "sdog","dogcatsdog"]```, for word ```dogcatsd... | 35 | 4 | [] | 14 |
concatenated-words | Python Explanation | python-explanation-by-awice-o3ok | Let's discuss whether a word should be included in our answer.\nConsider the word as a topologically sorted directed graph, where each node is a letter, and an | awice | NORMAL | 2016-12-18T04:52:06.675000+00:00 | 2018-10-03T18:57:56.014312+00:00 | 10,431 | false | Let's discuss whether a word should be included in our answer.\nConsider the word as a topologically sorted directed graph, where each node is a letter, and an edge exists from i to j if word[i:j] is in our wordlist, [and there is no edge from i=0 to j=len(word)-1]. We want to know if there is a path from beginning to... | 33 | 2 | [] | 11 |
concatenated-words | Simple Recursion and Optimization | Java C++ | simple-recursion-and-optimization-java-c-86lf | Intution\nFirst lets approach the easiest ones.\n\n1. Solution 1: a sub problem\n\tThe simple idea is we will break a string into 2 Strings and see if they are | jeevankumar159 | NORMAL | 2023-01-27T01:02:57.238395+00:00 | 2023-01-27T03:58:32.793328+00:00 | 3,355 | false | Intution\nFirst lets approach the easiest ones.\n\n1. Solution 1: a sub problem\n\tThe simple idea is we will break a string into 2 Strings and see if they are they are there in the array\n\teg [cat, s, cats]; \n\t\n written by @JayS03. Surprisingly, the runtime beats 100% of python 3 submissions.\n```\nclass Solution:\n ... | 32 | 1 | [] | 12 |
concatenated-words | Easyway Explanation every step | easyway-explanation-every-step-by-paul_d-j7qo | \nfor word in words:\n if dfs(word):\n\n\n# Taking word from wods list /array one by one\n\n\ndef dfs(word):\n for i in range(1, len(word) | paul_dream | NORMAL | 2020-09-30T11:45:52.600941+00:00 | 2020-10-24T04:23:35.533723+00:00 | 2,611 | false | ```\nfor word in words:\n if dfs(word):\n```\n\n# Taking word from wods list /array one by one\n\n```\ndef dfs(word):\n for i in range(1, len(word)):\n```\n.\n# travesing one by character which selecte from word list every time \n\n```\nprefix = word[:i]\n suffix = word[i:]\n```\n.\n# divide the w... | 31 | 1 | ['Python', 'Python3'] | 12 |
concatenated-words | having been troubled by this for a long time.... here is my pretty short java code beats 78% quite easy no comlicated data structure | having-been-troubled-by-this-for-a-long-ix3fq | ```\npublic List findAllConcatenatedWordsInADict(String[] words) {\n List list = new ArrayList<>();\n Set dictionary = new HashSet<>();\n f | jays03 | NORMAL | 2017-07-12T23:46:59.315000+00:00 | 2018-10-10T22:42:07.399446+00:00 | 4,082 | false | ```\npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> list = new ArrayList<>();\n Set<String> dictionary = new HashSet<>();\n for(String string : words) dictionary.add(string);\n for(String word:words) {\n dictionary.remove(word);\n i... | 29 | 2 | [] | 14 |
concatenated-words | 20 line C++ 169 ms Beats 100% & Why I think this problem is not properly judged. | 20-line-c-169-ms-beats-100-why-i-think-t-e4qa | The following simple naive brutal force easily beats 100% C++ submission from the past 6 months!\n\nYou know why your algorithm was slower?\nBecause you are too | fentoyal | NORMAL | 2017-05-19T08:51:44.967000+00:00 | 2018-10-24T22:10:18.813121+00:00 | 4,947 | false | The following simple naive brutal force easily beats 100% C++ submission from the past 6 months!\n\n**You know why your algorithm was slower?**\n**Because you are too smart!**\n\n DO NOT memoize the intermediate results and DO NOT use trie. The additional data structure slows the algorithm down!!\n\nThis is why I think... | 27 | 3 | [] | 8 |
concatenated-words | [PYTHON] , VERY EASY,DP, RECURSION, MEMOISATION, Space and time optimised | python-very-easydp-recursion-memoisation-t8ib | First Lets look at the recursion solution so that we get the clarity and then we can move to dp solution\n\nclass Solution:\n def findAllConcatenatedWordsInA | abhinay-thor | NORMAL | 2023-01-27T01:33:38.281549+00:00 | 2023-01-27T01:35:46.436770+00:00 | 2,955 | false | First Lets look at the recursion solution so that we get the clarity and then we can move to dp solution\n```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n # helper function to check if a given word can be formed by concatenating \n # two or more words i... | 26 | 1 | ['Dynamic Programming', 'Recursion', 'Python'] | 5 |
concatenated-words | C++ || Easy || NO DP | c-easy-no-dp-by-jenish_09-s3mb | \n\n# Code\n\nclass Solution {\npublic:\n map<string,int> m;\n bool cal(string &str,int idx,int cnt)\n {\n if(idx==str.size())\n retu | jenish_09 | NORMAL | 2023-01-27T05:19:47.650494+00:00 | 2023-01-27T05:19:47.650547+00:00 | 2,093 | false | \n\n# Code\n```\nclass Solution {\npublic:\n map<string,int> m;\n bool cal(string &str,int idx,int cnt)\n {\n if(idx==str.size())\n return cnt>1; // check atleat two string are concate\n string tmp="";\n for(int i=idx;i<str.size();i++)\n {\n tmp+=str[i];\n ... | 21 | 0 | ['String', 'C++'] | 4 |
concatenated-words | Simple Java Trie + DFS solution 144ms | simple-java-trie-dfs-solution-144ms-by-h-i5sl | Most of lines are adding words into Trie Tree \nThis solution is like putting two pointers to search through the tree. When find a word, put the other pointer b | huiyuyang | NORMAL | 2016-12-18T17:58:38.568000+00:00 | 2016-12-18T17:58:38.568000+00:00 | 10,562 | false | Most of lines are adding words into Trie Tree \nThis solution is like putting two pointers to search through the tree. When find a word, put the other pointer back on root then continue searching.\nBut I'm not sure about the time complexity of my solution. Suppose word length is len and there are n words. Is the time c... | 20 | 1 | [] | 17 |
concatenated-words | Python Trie solution explained | python-trie-solution-explained-by-skdoos-gy94 | This question is very similar to 208. Implement Trie (Prefix Tree) with one modification. Apart from searching for a word in the trie, we should also keep track | skdoosh | NORMAL | 2020-07-31T19:03:06.388159+00:00 | 2020-07-31T19:13:53.038182+00:00 | 2,090 | false | This question is very similar to [208. Implement Trie (Prefix Tree)](http://leetcode.com/problems/implement-trie-prefix-tree/) with one modification. Apart from searching for a word in the trie, we should also keep track of smaller words encountered during the search. \n\n1. We insert all the words into the `trie`. \n2... | 19 | 1 | ['Depth-First Search', 'Trie', 'Recursion', 'Python3'] | 6 |
concatenated-words | Python solutions: top-down DP, Trie + DFS | python-solutions-top-down-dp-trie-dfs-by-j7wg | Please see and vote for my Python DP solutions for\n139. Word Break\n140. Word Break II\n472. Concatenated Words\n\nMethod 1: top-down DP (444 ms, beat 52%)\nLe | otoc | NORMAL | 2019-06-28T22:36:16.776235+00:00 | 2022-08-16T04:29:03.819016+00:00 | 1,366 | false | Please see and vote for my Python DP solutions for\n[139. Word Break](https://leetcode.com/problems/word-break/discuss/322388/Standard-DP-solutions-(Bottom-up-Top-down))\n[140. Word Break II](https://leetcode.com/problems/word-break-ii/discuss/322400/Standard-Python-DP-solutions-(Bottom-up-Top-down))\n[472. Concatenate... | 19 | 1 | [] | 5 |
concatenated-words | Simple solution. Javascript Beats 90% with explanation | simple-solution-javascript-beats-90-with-pb36 | \n1. Use a set for quick lookup\n2. Call isConcat on each word. If a word\'s prefix is in the dictionary, see if the suffix can also be concatenated.\n3. You c | kenhufford | NORMAL | 2020-04-10T22:59:39.271071+00:00 | 2020-04-10T22:59:39.271111+00:00 | 1,483 | false | \n1. Use a set for quick lookup\n2. Call isConcat on each word. If a word\'s prefix is in the dictionary, see if the suffix can also be concatenated.\n3. You can use the dictionary as a memo, when you find a word that can be made via concatenation, you can store it in the dictionary\n4. When you loop through the words... | 18 | 1 | ['Depth-First Search', 'Recursion', 'JavaScript'] | 4 |
concatenated-words | A review of top solutions | a-review-of-top-solutions-by-yu6-ffbo | After studying the top solutions, I might not be the only one wondering which is the best and why. So I would like to share my understanding with this post.\n\n | yu6 | NORMAL | 2017-02-09T19:38:17.105000+00:00 | 2017-02-09T19:38:17.105000+00:00 | 2,600 | false | After studying the top solutions, I might not be the only one wondering which is the best and why. So I would like to share my understanding with this post.\n\nOne sub problem is word break. There are three ways to solve word break,[ DFS, BFS and DP](https://discuss.leetcode.com/topic/66356/evolve-from-brute-force-to-o... | 17 | 0 | ['C'] | 2 |
concatenated-words | java 41ms trie and dfs solution which beats 97% | java-41ms-trie-and-dfs-solution-which-be-kqnw | We can solve the problem in two steps:\n1. put the given words in a trie;\n2. For each word, dfs the trie (traverse characters in the word one by one). If the t | pangeneral | NORMAL | 2019-04-24T13:58:30.943419+00:00 | 2019-04-24T13:58:30.943464+00:00 | 1,946 | false | We can solve the problem in two steps:\n1. put the given words in a trie;\n2. For each word, dfs the trie (traverse characters in the word one by one). If the trie node of current character represent a word, then for next character, we search from the root node of trie. \n\n```\npublic List<String> findAllConcatenatedW... | 16 | 0 | ['Depth-First Search', 'Trie', 'Java'] | 4 |
concatenated-words | java hashset 48ms beats 100% | java-hashset-48ms-beats-100-by-lolozo-dc5n | \npublic class Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> ret = new ArrayList<>();\n Set | lolozo | NORMAL | 2018-07-04T22:28:36.096921+00:00 | 2018-07-04T22:28:36.096921+00:00 | 1,930 | false | ```\npublic class Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> ret = new ArrayList<>();\n Set<String> set = new HashSet<>();\n for (String word : words) {\n set.add(word);\n }\n for (String word : words) {\n ... | 16 | 0 | [] | 5 |
concatenated-words | Fast Python DP solution | fast-python-dp-solution-by-hongsenyu-2ni7 | \n\'\'\'\nIf a word can be Concatenated from shorter words, then word[:i] and word[i:] must also be Concatenated from shorter words.\nBuild results of word from | hongsenyu | NORMAL | 2020-02-26T06:35:48.466271+00:00 | 2020-02-26T06:35:48.466307+00:00 | 783 | false | ```\n\'\'\'\nIf a word can be Concatenated from shorter words, then word[:i] and word[i:] must also be Concatenated from shorter words.\nBuild results of word from results of word[:i] and word[i:]\nIterate i from range(1, len(word)) to avoid a word is Concatenated from itself.\nUse memorization to avoid repeat calculat... | 15 | 0 | ['Dynamic Programming'] | 3 |
concatenated-words | C++ Solutions, Backtrack, DP, or Trie. | c-solutions-backtrack-dp-or-trie-by-wang-8og0 | First, I provide my working solution using unorederd_set. But I think a better solution should use Trie. Though it passed all test cases, I always get MLE. But | wangxinbo | NORMAL | 2016-12-19T23:52:15.506000+00:00 | 2018-08-23T16:55:48.631569+00:00 | 5,210 | false | First, I provide my working solution using unorederd_set. But I think a better solution should use Trie. Though it passed all test cases, I always get MLE. But the java solution using Trie can be accepted. Did anybody have any suggestions about this? I have already made some optimization on it, e.g., a word that can be... | 14 | 0 | [] | 7 |
concatenated-words | ✅ fast C++ code | fast-c-code-by-coding_menance-44zy | Solution Code\nC++ []\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> wor | coding_menance | NORMAL | 2023-01-27T04:02:56.146265+00:00 | 2023-01-27T10:04:00.640925+00:00 | 956 | false | # Solution Code\n``` C++ []\nclass 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 in... | 13 | 0 | ['C++'] | 3 |
concatenated-words | 51ms easy Java Trie solution | 51ms-easy-java-trie-solution-by-bianhit-agg2 | \nclass Solution {\n TrieNode root = new TrieNode();\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> res = n | bianhit | NORMAL | 2018-08-14T18:27:42.757871+00:00 | 2018-09-30T21:18:37.871954+00:00 | 1,467 | false | ```\nclass Solution {\n TrieNode root = new TrieNode();\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> res = new ArrayList<>();\n build(words);\n for (String word : words) \n if (search(root,word,0,0))\n res.add(word);\n ... | 13 | 0 | [] | 1 |
concatenated-words | C++ 200ms straightforward Trie+DFS solution without DP | c-200ms-straightforward-triedfs-solution-urlz | \nclass Solution {\nprivate:\n struct Trie\n {\n vector<Trie*> children{26};\n bool end{false};\n };\n \n Trie* root;\n \n vo | ilovehawthorn | NORMAL | 2021-11-07T05:28:37.070688+00:00 | 2021-11-07T05:29:20.459563+00:00 | 816 | false | ```\nclass Solution {\nprivate:\n struct Trie\n {\n vector<Trie*> children{26};\n bool end{false};\n };\n \n Trie* root;\n \n void insert(string& s)\n {\n if (s.empty()) return;\n Trie* cur = root;\n for (char c:s)\n {\n if (cur->children[c-\'... | 12 | 1 | ['Depth-First Search', 'Trie', 'C'] | 2 |
concatenated-words | c++(124ms 98%) sorting & Trie & memorisation | c124ms-98-sorting-trie-memorisation-by-z-as9h | New version : fixed for new cases. In old version I want to not use memorisation, but for NEW case of test I need to do it and I done it\nRuntime: 164 ms, faste | zx007pi | NORMAL | 2021-10-26T08:37:21.607311+00:00 | 2022-02-09T15:31:37.740356+00:00 | 918 | false | **New version : fixed for new cases. In old version I want to not use memorisation, but for NEW case of test I need to do it and I done it**\nRuntime: 164 ms, faster than 97.29% of C++ online submissions for Concatenated Words.\nMemory Usage: 242.3 MB, less than 49.85% of C++ online submissions for Concatenated Words.\... | 12 | 0 | ['C', 'C++'] | 4 |
concatenated-words | 🔥C++|Template for Word Break I,II,Concatenated-words|All U Need✅ | ctemplate-for-word-break-iiiconcatenated-apib | Intuition\n Describe your first thoughts on how to solve this problem. \nIntuition for all the problems:\nAll the three given problems can be divided into sub- | Xahoor72 | NORMAL | 2023-01-27T21:27:25.000706+00:00 | 2023-01-27T21:27:25.000735+00:00 | 332 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntuition for all the problems:\nAll the three given problems can be divided into sub-problems .And If these subproblems individually satisfy the required conditions, then complete problem will also satisfy the same. And hence we can s... | 11 | 0 | ['Hash Table', 'Dynamic Programming', 'Backtracking', 'Depth-First Search', 'C++'] | 0 |
concatenated-words | 472. Concatenated Words - Analysis | 472-concatenated-words-analysis-by-hamle-x8ov | Concatenated Words \nGiven a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.\nA conca | hamlet_fiis | NORMAL | 2019-02-17T07:16:24.031105+00:00 | 2019-02-17T07:16:24.031183+00:00 | 3,954 | false | <h2>Concatenated Words</h2>\nGiven a list of words (<b>without duplicates</b>), please write a program that returns all concatenated words in the given list of words.\nA concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.\n\n**Example**\n<pre><strong>Inp... | 11 | 2 | ['Dynamic Programming', 'Trie'] | 4 |
concatenated-words | Simple DFS || No Trie || No DP || Easy to understand | simple-dfs-no-trie-no-dp-easy-to-underst-5wk2 | \nclass Solution {\npublic:\n int solve(set<string>&st, string& word, int start)\n {\n if (start >= word.size()) return 0;\n\n string strTil | mohakharjani | NORMAL | 2023-01-27T01:27:51.009418+00:00 | 2023-01-27T01:37:16.933168+00:00 | 1,438 | false | ```\nclass Solution {\npublic:\n int solve(set<string>&st, string& word, int start)\n {\n if (start >= word.size()) return 0;\n\n string strTillPivot = "";\n int mx = INT_MIN;\n for (int pivotIdx = start; pivotIdx < word.size(); pivotIdx++)\n {\n strTillPivot.push_bac... | 9 | 1 | ['Depth-First Search', 'C', 'C++'] | 1 |
concatenated-words | [C++] Simple C++ Code || No Trie || 73% time || 78% space | c-simple-c-code-no-trie-73-time-78-space-sx37 | If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n unord | _pros_ | NORMAL | 2022-07-19T07:27:02.049837+00:00 | 2022-07-19T07:28:04.247062+00:00 | 463 | false | # **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n unordered_map<string, int> um;\n vector<string> ans;\n bool dfs(string &str, int i)\n {\n if(i == str.size())\n {\n return... | 9 | 0 | ['Backtracking', 'Recursion', 'C'] | 1 |
concatenated-words | Python Fast Simple Top-Down Dynamic Programming | python-fast-simple-top-down-dynamic-prog-psjp | python\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n wordset = set(words)\n @cache\n de | ashkan-leo | NORMAL | 2022-05-11T01:54:09.257339+00:00 | 2022-05-11T01:54:09.257369+00:00 | 606 | false | ```python\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n wordset = set(words)\n @cache\n def iscat(word):\n for i in range(1, len(word)):\n if word[:i] in wordset and (word[i:] in wordset or iscat(word[i:])):\n ... | 9 | 0 | ['Python'] | 3 |
concatenated-words | JAVA DP + Trie 75ms | java-dp-trie-75ms-by-guiguia-pyor | Step 1: created Trie from words\nStep 2: check each word\n\tdp[i]: number of concatenated words for substring of word[i, word.length() - 1]\n\tfor each index i | guiguia | NORMAL | 2021-08-11T19:20:09.325434+00:00 | 2021-08-11T19:20:09.325463+00:00 | 373 | false | Step 1: created Trie from words\nStep 2: check each word\n\tdp[i]: number of concatenated words for substring of word[i, word.length() - 1]\n\tfor each index i at each word, check the second part of word[i, n -1] is a word.\n\tdp[i] >= 2 means it can be concatenated from two words \n\t\nTime complexity: O(m * n^2). ... | 9 | 0 | [] | 0 |
concatenated-words | ✅C++|Very Simple DP |Beats 90%🔥✔ | cvery-simple-dp-beats-90-by-xahoor72-a7ih | Intuition\n Describe your first thoughts on how to solve this problem. \nIdea is to check if a word can be constructed by the concatenation of other words in t | Xahoor72 | NORMAL | 2023-01-27T14:46:22.749063+00:00 | 2023-01-27T14:46:22.749096+00:00 | 718 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIdea is to check if a word can be constructed by the concatenation of other words in the set. Actually first fill all the word in aset that is a perfect data structure to check if a word s present or not . \n# Approach\n<!-- Describe you... | 8 | 0 | ['Hash Table', 'String', 'Dynamic Programming', 'Depth-First Search', 'C++'] | 0 |
concatenated-words | ✅ [C++]Easy solution with explanation ✅ | ceasy-solution-with-explanation-by-upadh-8wdh | Intuition\nYou don\'t need to find all the words you just need to check whether the words are made or not , so simply check for the word form (i to j) and then | upadhyayabhi0107 | NORMAL | 2023-01-27T05:56:15.037325+00:00 | 2023-01-27T06:40:54.991922+00:00 | 500 | false | # Intuition\nYou don\'t need to find all the words you just need to check whether the words are made or not , so simply check for the word form (i to j) and then call the check for j + 1;\n\n# Approach\nWhat Function findWord is doing ?\nIt makes a word from i till j where there is word , \neg : [cat , catanddog , and ... | 8 | 1 | ['Dynamic Programming', 'Depth-First Search', 'C++'] | 0 |
concatenated-words | Javascript 98.11% fast very very easy to understand solution with video explanation!!! | javascript-9811-fast-very-very-easy-to-u-4icr | If you like my video and explanation, Subscribe please!!! Thank you!!\n\nhttps://youtu.be/LRhVY83R9cI\n\n\n# Code\n\n/**\n * @param {string[]} words\n * @return | rlawnsqja850 | NORMAL | 2023-01-27T01:06:28.011483+00:00 | 2023-01-27T01:06:28.011513+00:00 | 1,042 | false | If you like my video and explanation, Subscribe please!!! Thank you!!\n\nhttps://youtu.be/LRhVY83R9cI\n\n\n# Code\n```\n/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar findAllConcatenatedWordsInADict = function(words) {\n const set = new Set(words);\n let res = []\n\n let isValid = (word) =>{\... | 8 | 0 | ['JavaScript'] | 2 |
concatenated-words | Java | Trie & Sort & DFS | 91ms | Some thoughts. | java-trie-sort-dfs-91ms-some-thoughts-by-ri0b | Sort it by length in ascending order because we only need to try to form the current string with shorter strings.\nThen we construct the trie as we go and do a | Student2091 | NORMAL | 2022-07-05T07:19:40.199767+00:00 | 2022-07-05T07:42:19.606088+00:00 | 565 | false | Sort it by length in ascending order because we only need to try to form the current string with shorter strings.\nThen we construct the trie as we go and do a dfs on each word.\n\nFor the DFS, we generally have two possible options:\n- Continue with the current word\n- If the current index has a valid word ended there... | 8 | 0 | ['Trie', 'Java'] | 1 |
concatenated-words | [Python]14 line DP with inline explanation | python14-line-dp-with-inline-explanation-rd95 | \nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n \n wordSet = set(words)\n ans = []\n | diihuu | NORMAL | 2021-02-09T19:07:13.958599+00:00 | 2021-03-03T04:25:21.702074+00:00 | 609 | false | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n \n wordSet = set(words)\n ans = []\n # 1) For each word w, For loop w[:i] \n # 2) check if the front segment[0:j] is in wordSet and if the [j+1: i] is in the wordset\n # EDGE C... | 8 | 0 | [] | 1 |
concatenated-words | Easy Python | 100% Speed | Highly Optimized | easy-python-100-speed-highly-optimized-b-0ajx | Easy Python | 100% Speed | Highly Optimized\n\nThe Python code below corresponds to a simple solution based on:\n\n1. Matching substrings against a global set ( | aragorn_ | NORMAL | 2020-07-20T21:33:58.436965+00:00 | 2020-09-04T23:06:02.323722+00:00 | 1,784 | false | **Easy Python | 100% Speed | Highly Optimized**\n\nThe Python code below corresponds to a simple solution based on:\n\n1. Matching substrings against a global set (I experimented using "Tries" originally, but they don\'t provide any benefits).\n\n2. Using Binary Search to look for compatible substring lengths (the proc... | 8 | 1 | ['Python', 'Python3'] | 5 |
concatenated-words | Short and easy recursive solution | short-and-easy-recursive-solution-by-ani-9kmh | Use ranges to split a particular word into two: w[..i] and w[i..]:\ncsharp\npublic class Solution\n{\n public IList<string> FindAllConcatenatedWordsInADict(s | anikit | NORMAL | 2023-01-27T11:05:58.225271+00:00 | 2023-01-27T11:30:52.046667+00:00 | 1,394 | false | Use ranges to split a particular word into two: `w[..i]` and `w[i..]`:\n```csharp\npublic class Solution\n{\n public IList<string> FindAllConcatenatedWordsInADict(string[] words)\n {\n HashSet<string> ws = new(words);\n return words.Where(w => IsConcatenated(w)).ToList();\n\n bool IsConcatena... | 7 | 0 | ['Depth-First Search', 'Recursion', 'C#'] | 0 |
concatenated-words | JAVA || EASY UNDERSTAING || USING RECURSION || DFS | java-easy-understaing-using-recursion-df-raqo | Code\n\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String>al=new ArrayList<>();\n Set<Stri | shaikhu3421 | NORMAL | 2023-01-27T03:15:30.453714+00:00 | 2023-01-27T03:15:30.453765+00:00 | 1,856 | false | # Code\n```\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String>al=new ArrayList<>();\n Set<String>hs=new HashSet<>();\n for(String i:words) hs.add(i);\n Map<String,Integer>hm=new HashMap<>();\n for(String i:words) if(check(i,hs,h... | 7 | 0 | ['Depth-First Search', 'Java'] | 4 |
concatenated-words | ✔️ [Python3] TRIE WITH RECURSION ᕕ( ᐛ )ᕗ, Explained | python3-trie-with-recursion-fi-waa-fo-ex-jqvr | UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.\n\nWe create a trie data structure from all given words. Then w | artod | NORMAL | 2022-06-24T04:05:10.750492+00:00 | 2022-06-24T04:05:10.750525+00:00 | 566 | false | **UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nWe create a trie data structure from all given words. Then we iterate over the characters of every word. When we see that a current prefix is in the trie, we call a recursive function asking whether the slice of the ... | 7 | 0 | ['Python3'] | 0 |
concatenated-words | C++ Soln || Trie + DFS | c-soln-trie-dfs-by-mitedyna-5l2m | \nclass Solution {\npublic:\n struct trie{\n trie* child[26];\n bool isend;\n };\n trie* root;\n trie* getnode(){\n trie* node= | mitedyna | NORMAL | 2021-05-30T23:29:14.543466+00:00 | 2021-05-30T23:29:14.543507+00:00 | 767 | false | ```\nclass Solution {\npublic:\n struct trie{\n trie* child[26];\n bool isend;\n };\n trie* root;\n trie* getnode(){\n trie* node=new trie;\n for(int i=0;i<26;i++){\n node->child[i]=NULL;\n }\n node->isend=false;\n return node;\n }\n void add... | 7 | 2 | ['Depth-First Search', 'Trie', 'C'] | 2 |
concatenated-words | [Recursion, Memoization] JS Solution | recursion-memoization-js-solution-by-hbj-25s8 | \nvar findAllConcatenatedWordsInADict = function(words) {\n let m = new Map(), memo = new Map();\n let res = [];\n for (let i = 0; i < words.length; i+ | hbjorbj | NORMAL | 2020-11-13T04:02:29.298713+00:00 | 2020-11-17T22:41:17.811743+00:00 | 807 | false | ```\nvar findAllConcatenatedWordsInADict = function(words) {\n let m = new Map(), memo = new Map();\n let res = [];\n for (let i = 0; i < words.length; i++) {\n m.set(words[i], 1);\n }\n for (let i = 0; i < words.length; i++) {\n if (isConcat(words[i], m, memo)) res.push(words[i]);\n }\n... | 7 | 0 | ['JavaScript'] | 3 |
concatenated-words | 📌📌Python3 || ⚡347 ms, faster than 91.39% of Python3 | python3-347-ms-faster-than-9139-of-pytho-i1vb | \ndef findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n wordset = set(words)\n result = []\n def dfs(word, wordset):\ | harshithdshetty | NORMAL | 2023-01-27T12:33:07.958861+00:00 | 2023-01-27T12:33:07.958926+00:00 | 1,003 | false | ```\ndef findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n wordset = set(words)\n result = []\n def dfs(word, wordset):\n if word == "":\n return True\n for i in range(len(word)):\n if word[:i+1] in wordset:\n ... | 6 | 1 | ['Depth-First Search', 'Ordered Set', 'Python', 'Python3'] | 1 |
concatenated-words | ✅ C++ || ✅ Explained || ✅ Simple approach ||🚀 EASY RECURSION || Using SET | c-explained-simple-approach-easy-recursi-r1l9 | PLZ UPVOTE\n\n\n# Code\n\nclass Solution {\npublic:\n\n //Our lc function breaks the word into two parts left and right\n // and check if these are alread | Sarthakberi | NORMAL | 2023-01-27T06:34:45.307019+00:00 | 2023-01-27T06:35:55.437649+00:00 | 750 | false | # PLZ UPVOTE\n\n\n# Code\n```\nclass Solution {\npublic:\n\n //Our lc function breaks the word into two parts left and right\n // and check if these are already present in our dictionary \n //o... | 6 | 0 | ['Array', 'String', 'Recursion', 'Ordered Set', 'C++'] | 1 |
concatenated-words | C++ || EASY TO UNDERSTAND || Simple BackTracking Siolution | c-easy-to-understand-simple-backtracking-rb1q | \nclass Solution {\npublic:\n set<string> dict;\n bool check(string &word,int c)\n {\n if(word.size()==0)\n {\n // cout<<c<<en | aarindey | NORMAL | 2022-07-08T01:09:05.435990+00:00 | 2022-07-08T01:09:05.436032+00:00 | 320 | false | ```\nclass Solution {\npublic:\n set<string> dict;\n bool check(string &word,int c)\n {\n if(word.size()==0)\n {\n // cout<<c<<endl;\n if(c>=2)\n return true;\n \n return false;\n }\n\n for(int i=1;i<=word.size();i++)\n {... | 6 | 0 | [] | 1 |
concatenated-words | My simple Java Solution using DP. No sort. | my-simple-java-solution-using-dp-no-sort-ufqx | \nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> result = new ArrayList<>();\n Set<Str | sumitrawat | NORMAL | 2020-09-05T08:34:03.233003+00:00 | 2020-09-05T08:34:03.233050+00:00 | 842 | false | ```\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> result = new ArrayList<>();\n Set<String> set = new HashSet<>();\n for(String word: words)\n set.add(word);\n for(String word: words){\n if(helper(word, set))... | 6 | 0 | ['Dynamic Programming', 'Java'] | 5 |
concatenated-words | Java Nice & Small, whats the TimeComplexity? | java-nice-small-whats-the-timecomplexity-y3fh | \nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> aList = new ArrayList<>();\n if(words | nirmal4343 | NORMAL | 2020-05-17T22:08:09.784089+00:00 | 2020-05-17T22:08:09.784166+00:00 | 617 | false | ```\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> aList = new ArrayList<>();\n if(words.length == 0) return aList;\n Set<String> wordSet = new HashSet<>();\n for (String string : words) {\n wordSet.add(string);\n ... | 6 | 0 | ['Java'] | 2 |
concatenated-words | python concise dfs solution | python-concise-dfs-solution-by-nio_up_to-60pp | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:#dfs to search.\n def dfs(w,oneGood):#return True or F | NIO_up_to_moon | NORMAL | 2019-11-07T00:18:18.117086+00:00 | 2019-11-07T00:18:18.117134+00:00 | 408 | false | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:#dfs to search.\n def dfs(w,oneGood):#return True or False\n if w in Set and oneGood:\n return True\n if w in memo:\n return memo[w]\n for i in range(l... | 6 | 0 | [] | 0 |
concatenated-words | python trie solution | python-trie-solution-by-shuuchen-bp45 | sort words by word length, so that short words are inserted firstly\n* insert words into trie one by one, if all of sub-words already exist in trie, return Fals | shuuchen | NORMAL | 2019-10-31T06:20:21.385113+00:00 | 2019-10-31T06:20:21.385163+00:00 | 460 | false | * sort words by word length, so that short words are inserted firstly\n* insert words into trie one by one, if all of sub-words already exist in trie, return False.\n\n```\nclass TrieNode:\n def __init__(self):\n self.isWord = False\n self.children = collections.defaultdict(TrieNode)\n\nclass Trie:\n ... | 6 | 0 | [] | 1 |
concatenated-words | O(N*L) | O(N*L) | Python Solution | Explained | onl-onl-python-solution-explained-by-tfd-eprj | Hello Tenno Leetcoders, \n\nFor this problem, we want to return all non duplicated concatenated words\n\nThis problem has the same logic as 139. Word Break. Th | TFDLeeter | NORMAL | 2023-01-27T18:25:30.926957+00:00 | 2023-01-27T18:25:46.928429+00:00 | 482 | false | Hello **Tenno Leetcoders**, \n\nFor this problem, we want to return all non duplicated `concatenated words`\n\nThis problem has the same logic as `139. Word Break`. This problem has its differences though because we want only words that are concatenated by 2 or more other words\n\nWe can use `Dynamic Programming` to b... | 5 | 0 | ['Dynamic Programming', 'Python', 'Python3'] | 3 |
concatenated-words | C++ || Simple || Brute Force Recursion with Memoization || 🔥🔥 | c-simple-brute-force-recursion-with-memo-v84p | Intuition\nWe check for each word given and if it is comprised entirely of at least two shorter words in the given array then we store it in our ans vector.\n\n | i_anurag_mishra | NORMAL | 2023-01-27T16:35:39.294393+00:00 | 2023-08-07T10:16:34.641159+00:00 | 235 | false | # Intuition\nWe check for each word given and if it is comprised entirely of at least two shorter words in the given array then we store it in our ans vector.\n\n# Approach\nIterate through the each word. If upto any particular index, it is present in given vector then call recursively for next indices. Cnt shows how m... | 5 | 0 | ['Dynamic Programming', 'Recursion', 'C++'] | 2 |
concatenated-words | JAVA | Simple Recursion | Explained ✅ | java-simple-recursion-explained-by-souri-nbc2 | ---\n# Please Upvote \uD83D\uDE07\n---\njava []\nclass Solution {\n // globally declare a hashset to store all the words \n private Set<String> set = new | sourin_bruh | NORMAL | 2023-01-27T16:31:28.189099+00:00 | 2023-01-28T11:04:30.861867+00:00 | 852 | false | ---\n# Please Upvote \uD83D\uDE07\n---\n``` java []\nclass Solution {\n // globally declare a hashset to store all the words \n private Set<String> set = new HashSet<>();\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n // add the words to the set\n for (String w : words)... | 5 | 0 | ['String', 'Recursion', 'Java'] | 3 |
concatenated-words | Java dp 22 lines and beat 90% with comments | java-dp-22-lines-and-beat-90-with-commen-ny7u | This is the medium question "139. Word Break" + a for loop. \nIf the input size of the list is N and the average of the word length is M.\nTo solve Leetcode 139 | yupeng1127 | NORMAL | 2022-03-07T06:42:48.345937+00:00 | 2022-03-07T06:42:48.345962+00:00 | 642 | false | This is the medium question "139. Word Break" + a for loop. \nIf the input size of the list is N and the average of the word length is M.\nTo solve Leetcode 139, we have two dp approaches:\n1.For each position in a word, we loop through all the words in the List and update the dp arrays. BigO: N * M * N\n2.For each wo... | 5 | 0 | ['Dynamic Programming', 'Java'] | 1 |
concatenated-words | Python | Trie | python-trie-by-__aj-d15d | \tclass Trie:\n\n\t\tdef init(self):\n\t\t\tself.root = dict()\n\n\t\tdef insert(self, words):\n\t\t\tfor word in words:\n\t\t\t\tcurrent = self.root\n\t\t\t\tf | __AJ__ | NORMAL | 2021-12-20T09:37:27.905289+00:00 | 2021-12-20T09:37:27.905430+00:00 | 1,139 | false | \tclass Trie:\n\n\t\tdef __init__(self):\n\t\t\tself.root = dict()\n\n\t\tdef insert(self, words):\n\t\t\tfor word in words:\n\t\t\t\tcurrent = self.root\n\t\t\t\tfor char in word:\n\t\t\t\t\tif char not in current:\n\t\t\t\t\t\tcurrent[char] = dict()\n\t\t\t\t\tcurrent = current[char]\n\t\t\t\tcurrent[\'*\'] = \'*\'\n... | 5 | 1 | ['Trie', 'Python', 'Python3'] | 1 |
concatenated-words | Java: Trie | java-trie-by-ankurpremi-30pt | Note: With the new test cases this solution gives TLE.\n\n\n\n\npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n TrieNode root = b | ankurpremi | NORMAL | 2020-12-06T18:42:24.895938+00:00 | 2020-12-28T17:31:11.369099+00:00 | 463 | false | Note: With the new test cases this solution gives TLE.\n\n\n```\n\npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n TrieNode root = buildTrie(words);\n List<String> result = new ArrayList();\n for(String word : words){\n if(searchWords(root, word, 0, 0))\n ... | 5 | 0 | [] | 1 |
concatenated-words | [Java] Clean code with Trie | java-clean-code-with-trie-by-algorithmim-xko7 | \npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> result = new ArrayList<>(); \n Trie root = new Trie();\ | algorithmimplementer | NORMAL | 2020-01-26T18:41:58.301695+00:00 | 2020-01-26T18:43:32.974392+00:00 | 308 | false | ``` \npublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> result = new ArrayList<>(); \n Trie root = new Trie();\n // Insert each word \n for (String word : words) {\n if (word.length() == 0) continue;\n Trie node = root; \n ... | 5 | 0 | [] | 0 |
concatenated-words | 💡JavaScript Solution | javascript-solution-by-aminick-0c3b | The idea\n1. Sort the array by length\n2. Use dynamic programming (bottom up) to check whether array[0,i-1] is a concatenated word\n3. Build the dp array as we | aminick | NORMAL | 2019-12-05T11:17:11.341210+00:00 | 2019-12-05T11:17:11.341243+00:00 | 641 | false | ### The idea\n1. Sort the array by length\n2. Use dynamic programming (bottom up) to check whether array[0,i-1] is a concatenated word\n3. Build the dp array as we iterate through the word from left to right using `end` pointer. Iterate array[0, end-1] use another point `start`. This way, we essentially split the quest... | 5 | 0 | ['JavaScript'] | 1 |
concatenated-words | [Kotlin] Dynamic Programming Word Concatenation Finder | kotlin-dynamic-programming-word-concaten-asdu | Intuition\nTo solve this problem, we can use dynamic programming. We iterate through each word in the input list and check if it can be formed by concatenating | teogor | NORMAL | 2024-04-14T12:02:24.541308+00:00 | 2024-04-14T12:02:24.541339+00:00 | 10 | false | # Intuition\nTo solve this problem, we can use dynamic programming. We iterate through each word in the input list and check if it can be formed by concatenating shorter words from the list.\n\n# Approach\n1. **Word Set Creation**: We start by creating a set called `wordSet` to store all the words in the input list. Th... | 4 | 0 | ['Array', 'String', 'Dynamic Programming', 'Kotlin'] | 0 |
concatenated-words | 472: Solution with step by step explanation | 472-solution-with-step-by-step-explanati-sjff | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Create a set of all words in the given list.\n2. Define a recursive fu | Marlen09 | NORMAL | 2023-03-10T17:29:50.349903+00:00 | 2023-03-10T17:29:50.349944+00:00 | 489 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Create a set of all words in the given list.\n2. Define a recursive function called isConcat to check if a word is concatenated.\n3. Memoize the isConcat function using the functools.lru_cache decorator to cache its resul... | 4 | 0 | ['Array', 'Dynamic Programming', 'Depth-First Search', 'Python', 'Python3'] | 0 |
concatenated-words | 🗓️ Daily LeetCoding Challenge January, Day 27 | daily-leetcoding-challenge-january-day-2-46wr | This problem is the Daily LeetCoding Challenge for January, Day 27. Feel free to share anything related to this problem here! You can ask questions, discuss wha | leetcode | OFFICIAL | 2023-01-27T00:00:32.246772+00:00 | 2023-01-27T00:00:32.246844+00:00 | 3,267 | false | This problem is the Daily LeetCoding Challenge for January, Day 27.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please c... | 4 | 0 | [] | 18 |
concatenated-words | JAVA || HashSet || EFFICIENT APPOACH || LEARNER FRIENDLY || RECURSION | java-hashset-efficient-appoach-learner-f-wbqg | \nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> result = new ArrayList<>();\n \n | duke05 | NORMAL | 2022-10-10T18:09:29.843141+00:00 | 2022-10-10T19:16:35.992778+00:00 | 660 | false | ```\nclass Solution {\n public List<String> findAllConcatenatedWordsInADict(String[] words) {\n List<String> result = new ArrayList<>();\n \n Set<String> dict = new HashSet<>(Arrays.asList(words));\n \n for (String word : words) {\n if(form(word, dict)) {\n re... | 4 | 0 | ['Recursion', 'Java'] | 0 |
concatenated-words | Concatenated Words | Python3 Solution | with comments | Time complexity analysis | concatenated-words-python3-solution-with-jaqi | \'\'\'\n\n\tdef findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n # creating a hashset of words for faster look-up\n wordset | tushar_goel | NORMAL | 2021-11-30T18:11:53.405656+00:00 | 2021-11-30T18:11:53.405701+00:00 | 266 | false | \'\'\'\n\n\tdef findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n # creating a hashset of words for faster look-up\n wordset = set(words)\n # List to store the final desired output\n result = []\n # Hashmap for keeping account of word of the wordset\n dict... | 4 | 0 | ['Depth-First Search', 'Recursion', 'Ordered Set'] | 1 |
concatenated-words | Python | Beats 97% runtime | Trie | python-beats-97-runtime-trie-by-rajatrai-k7wt | \nclass Solution:\ndef findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n\ttrie={}\n\tfor w in words:\n\t\troot=trie\n\t\tfor s in w:\n\t\t | rajatrai1206 | NORMAL | 2021-11-12T07:02:02.512582+00:00 | 2021-11-12T07:02:02.512625+00:00 | 682 | false | ```\nclass Solution:\ndef findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n\ttrie={}\n\tfor w in words:\n\t\troot=trie\n\t\tfor s in w:\n\t\t\tif s not in root:\n\t\t\t\troot[s]={}\n\t\t\troot=root[s]\n\t\troot["$"]=True\n\n\t@lru_cache(None)\n\tdef find(w):\n\t\tif not w:\n\t\t\treturn True\n\t\t... | 4 | 0 | ['Trie', 'Python'] | 0 |
concatenated-words | (C++) 472. Concatenated Words | c-472-concatenated-words-by-qeetcode-n4xe | \n\nclass TrieNode {\npublic: \n TrieNode* children[26] = {nullptr}; \n bool word = false; \n ~TrieNode() {\n for (auto& child : children) \n | qeetcode | NORMAL | 2021-09-15T01:25:08.341873+00:00 | 2021-09-15T01:25:08.341906+00:00 | 532 | false | \n```\nclass TrieNode {\npublic: \n TrieNode* children[26] = {nullptr}; \n bool word = false; \n ~TrieNode() {\n for (auto& child : children) \n delete child; \n }\n}; \n\nclass Trie {\n TrieNode* root = nullptr; \npublic: \n Trie() { root = new TrieNode(); }\n \n ~Trie() { del... | 4 | 0 | ['C'] | 1 |
concatenated-words | [Python3] hash | python3-hash-by-ye15-p3kn | \n\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n seen = set(words)\n \n @cache\n | ye15 | NORMAL | 2021-09-14T22:20:02.151032+00:00 | 2021-09-15T01:43:39.197435+00:00 | 421 | false | \n```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n seen = set(words)\n \n @cache\n def fn(word):\n """Return True if input is a concatenated word."""\n for i in range(1, len(word)): \n prefix = word[:i]... | 4 | 0 | ['Python3'] | 2 |
concatenated-words | Two Approaches 1.) Memo + DFS 2.) DP | two-approaches-1-memo-dfs-2-dp-by-agingw-j472 | Memo + DFS:\n\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n wordSet = set(words)\n rv = []\n | agingwolverine | NORMAL | 2021-09-08T02:34:35.906276+00:00 | 2021-09-08T02:41:15.870113+00:00 | 695 | false | Memo + DFS:\n```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n wordSet = set(words)\n rv = []\n for wd in words:\n memo = {}\n wordSet.remove(wd)\n if len(wd) > 0 and self.dfs(wd, wordSet, memo):\n r... | 4 | 0 | ['Depth-First Search', 'Python'] | 0 |
concatenated-words | C# DP solution | c-dp-solution-by-newbiecoder1-d83l | \npublic class Solution {\n public IList<string> FindAllConcatenatedWordsInADict(string[] words) {\n \n List<string> res = new List<string>();\ | newbiecoder1 | NORMAL | 2021-07-05T22:13:49.379846+00:00 | 2021-07-05T22:13:49.379876+00:00 | 396 | false | ```\npublic class Solution {\n public IList<string> FindAllConcatenatedWordsInADict(string[] words) {\n \n List<string> res = new List<string>();\n if(words == null || words.Length == 0)\n return res;\n \n HashSet<string> wordSet = new HashSet<string>();\n Array.Sor... | 4 | 0 | [] | 1 |
concatenated-words | Java || DFS || Similar to Word Break | java-dfs-similar-to-word-break-by-legend-kb8b | \n\t// O(log(words.lengthlog(words.length)) + O(words.lengthwords[i].length^2))\n\tpublic List findAllConcatenatedWordsInADict(String[] words) {\n\n\t\tList res | LegendaryCoder | NORMAL | 2021-02-27T03:44:51.522889+00:00 | 2021-02-27T05:14:09.518989+00:00 | 425 | false | \n\t// O(log(words.length*log(words.length)) + O(words.length*words[i].length^2))\n\tpublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n\n\t\tList<String> res = new ArrayList<String>();\n\t\tif (words.length == 1)\n\t\t\treturn res;\n\n\t\tArrays.sort(words, new Comparator<String>() {\n\t\t\t@Overri... | 4 | 0 | [] | 0 |
concatenated-words | Trie + DFS Solution [C++] | trie-dfs-solution-c-by-kalel_ms-33qu | \nclass TrieNode {\npublic:\n bool isKey = false;\n TrieNode* child[26];\n};\n\nclass Solution {\npublic:\n TrieNode* root = new TrieNode();\n \n | kalEl_ | NORMAL | 2020-09-08T05:20:13.041815+00:00 | 2020-09-08T05:20:13.041868+00:00 | 433 | false | ```\nclass TrieNode {\npublic:\n bool isKey = false;\n TrieNode* child[26];\n};\n\nclass Solution {\npublic:\n TrieNode* root = new TrieNode();\n \n void addWord (string word) {\n TrieNode* curr = root;\n for(char c : word) {\n if(!curr->child[c - \'a\'])\n curr->c... | 4 | 0 | ['Depth-First Search', 'Trie', 'Recursion', 'C++'] | 2 |
concatenated-words | Python | Trie + Memo | Simple | python-trie-memo-simple-by-ared25-gg4e | \nclass Solution:\n def findAllConcatenatedWordsInADict(self, words):\n t, memo, res = Trie(), {}, []\n for word in words:\n t.add(w | ared25 | NORMAL | 2020-02-17T07:17:13.330974+00:00 | 2021-11-16T00:24:13.593942+00:00 | 1,289 | false | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words):\n t, memo, res = Trie(), {}, []\n for word in words:\n t.add(word)\n for word in words:\n if t.helper(word, 0, len(word) - 1, 0, memo):\n res.append(word)\n return res\n\n\nclass ... | 4 | 0 | ['Trie', 'Recursion', 'Python'] | 7 |
concatenated-words | Python DP Simple Solution with 3 Lines | python-dp-simple-solution-with-3-lines-b-f52e | \nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n s = set(words)\n \n memo = {}\n d | thseong | NORMAL | 2019-11-22T09:50:57.674787+00:00 | 2019-11-28T09:04:21.770813+00:00 | 635 | false | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n s = set(words)\n \n memo = {}\n def isConcatenatedWord(w):\n if w in memo: return memo[w]\n \n for i in range(1, len(w)):\n if w[:i] not in s:... | 4 | 0 | ['Dynamic Programming', 'Python3'] | 1 |
concatenated-words | Python naive solution beats 99% and 100% | python-naive-solution-beats-99-and-100-b-gkvg | \nclass Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n words = set(words)\n\t\t\n def is_concatenated(word):\n | jdjw | NORMAL | 2019-10-20T04:37:10.677725+00:00 | 2019-10-20T04:37:29.302051+00:00 | 334 | false | ```\nclass Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n words = set(words)\n\t\t\n def is_concatenated(word):\n for i in range(1, len(word)):\n if word[:i] in words and (word[i:] in words or is_concatenated(word[i:])):\n return Tru... | 4 | 0 | [] | 0 |
concatenated-words | very simple and clean solutions on Java (2 approaches) | very-simple-and-clean-solutions-on-java-5voev | \n\tApproach #1 Backtracking:\n \n\tpublic List findAllConcatenatedWordsInADict(String[] words) {\n Set hash = new HashSet<>(Arrays.asList(words));\n\n | jisqaqov | NORMAL | 2019-10-06T08:22:05.621525+00:00 | 2019-10-06T08:22:35.556186+00:00 | 537 | false | \n\tApproach #1 Backtracking:\n \n\tpublic List<String> findAllConcatenatedWordsInADict(String[] words) {\n Set<String> hash = new HashSet<>(Arrays.asList(words));\n\n List<String> list = new ArrayList<>();\n for (String word : words) {\n if (concatenated(word, 0, hash)) {\n list.add(w... | 4 | 0 | ['Backtracking', 'Depth-First Search', 'Trie'] | 2 |
concatenated-words | C# HashSet + WordBreak | c-hashset-wordbreak-by-bacon-pp0j | \npublic class Solution {\n public IList<string> FindAllConcatenatedWordsInADict(string[] words) {\n var result = new List<string>();\n if (wor | bacon | NORMAL | 2019-07-31T03:57:02.665885+00:00 | 2019-07-31T03:57:02.665940+00:00 | 550 | false | ```\npublic class Solution {\n public IList<string> FindAllConcatenatedWordsInADict(string[] words) {\n var result = new List<string>();\n if (words.Length <= 2) return result;\n\n var wordSet = new HashSet<string>(words);\n foreach (var word in words) {\n if (word == "") conti... | 4 | 0 | [] | 0 |
concatenated-words | Python DFS Solution | python-dfs-solution-by-ycyc-sfnr | \nclass Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n """\n :type words: List[str]\n :rtype: List[str]\n | ycyc | NORMAL | 2016-12-29T01:28:15.776000+00:00 | 2016-12-29T01:28:15.776000+00:00 | 1,206 | false | ```\nclass Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n """\n :type words: List[str]\n :rtype: List[str]\n """\n word_set = set(words)\n ans = []\n def helper(w, cur, cnt):\n if cur == len(w):\n if cnt > 1:\n ... | 4 | 0 | [] | 2 |
concatenated-words | [Python3] Simple DFS & Set: 111ms | Beats 91.31% | python3-beats-90-simple-dfs-set-solution-p27f | IntuitionThe key insight is that each word in the list can potentially be formed by concatenating other words from the list. We need to check if we can split a | Leo_Ouyang | NORMAL | 2024-12-26T21:06:21.824411+00:00 | 2025-01-08T21:38:44.119323+00:00 | 330 | false | # Intuition
The key insight is that each word in the list can potentially be formed by concatenating other words from the list. We need to check if we can split a word into multiple valid words that exist in our dictionary. This is a perfect case for using recursion with dynamic programming principles.
# Approach
1. F... | 3 | 0 | ['Python3'] | 0 |
concatenated-words | Clean Java Solution With Trie + DP | clean-java-solution-with-trie-dp-by-bard-0te9 | Intuition\nBuild the Trie with the Input words, then recursively check whether each word can be broken down such that all partitions are present in the Trie\n\n | bardock | NORMAL | 2023-11-05T00:18:49.584966+00:00 | 2023-11-05T00:18:49.584989+00:00 | 229 | false | # Intuition\nBuild the Trie with the Input words, then recursively check whether each word can be broken down such that all partitions are present in the Trie\n\n# Approach\nI did not come up with this, original solution is by @gracemeng\n\n\n# Code\n```\nclass Solution {\n class Trie {\n Map<Character, Trie>... | 3 | 0 | ['Java'] | 0 |
concatenated-words | [C++] | Trie solution | c-trie-solution-by-ometek-3njb | Intuition\nBy storing the data in a Trie tree structure we will be able to check the presence of the word in O(s) time, where s is the lenghts of the word. As t | Ometek | NORMAL | 2023-01-27T13:53:10.932990+00:00 | 2023-01-27T13:53:10.933020+00:00 | 43 | false | # Intuition\nBy storing the data in a Trie tree structure we will be able to check the presence of the word in O(s) time, where s is the lenghts of the word. As the words are relatively short - 30 characters max - this structure allows us to do that very efficiently.\n\n# Approach\n1. Initialize a trie tree\n2. Add ele... | 3 | 0 | ['Depth-First Search', 'Trie', 'C++'] | 0 |
concatenated-words | ✅Accepted || ✅Short & Simple || ✅Best Method || ✅Easy-To-Understand | accepted-short-simple-best-method-easy-t-y7il | \n# Code\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> st(words.begin | sanjaydwk8 | NORMAL | 2023-01-27T08:02:19.040735+00:00 | 2023-01-27T08:02:19.040775+00:00 | 217 | false | \n# Code\n```\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n unordered_set<string> st(words.begin(), words.end());\n vector<string> ans;\n unordered_map<string, int> mp;\n for(string s:st)\n mp[s]++;\n for(string s:st)\... | 3 | 0 | ['C++'] | 0 |
concatenated-words | Maps cpp solve✅✅ Map+Recursive Solve | maps-cpp-solve-maprecursive-solve-by-mil-4qqg | Intuition\n Describe your first thoughts on how to solve this problem. \nMap stores the words \n# Approach\n Describe your approach to solving the problem. \nre | milan2001 | NORMAL | 2023-01-27T06:59:04.162894+00:00 | 2023-01-27T06:59:19.201408+00:00 | 515 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMap stores the words \n# Approach\n<!-- Describe your approach to solving the problem. -->\nrecursive approaches\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add you... | 3 | 0 | ['Ordered Map', 'C++'] | 0 |
concatenated-words | ✅C++|| Recursion || Memoization || Very Easy || Approach || Complexity | c-recursion-memoization-very-easy-approa-qixf | Intuition\n Describe your first thoughts on how to solve this problem. \nRecursion\n\n# Approach\n Describe your approach to solving the problem. \n- store all | sunnyjha1512002 | NORMAL | 2023-01-27T06:50:21.816048+00:00 | 2023-01-27T06:50:21.816110+00:00 | 321 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nRecursion\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- store all strings in set to find it in fast.\n- traverse on each word\n - check if it can func(concat) or not\n - push in ans\n\n\n## concat fun... | 3 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
concatenated-words | Partition Dp Solution || C++ || Easy Understanding | partition-dp-solution-c-easy-understandi-32te | \n\nT.C : O(n*s[i].length)\nS.C : O(n * s[i].length)\n\n\n\nclass Solution {\npublic:\n unordered_set<string> mp;\n // dp[i] = number of ways to partition | krunal_078 | NORMAL | 2023-01-27T05:49:43.172128+00:00 | 2023-01-27T05:53:01.002802+00:00 | 168 | false | \n\n**T.C : O(n*s[i].length)\nS.C : O(n * s[i].length)**\n\n\n```\nclass Solution {\npublic:\n unordered_set<string> mp;\n // dp[i] = number of ways to partition strings such that each substring is in the words;\n int rec(string &s,int n,int i,vector<int> &dp){\n if(i>=n) return true;\n if(dp[i]!... | 3 | 0 | ['Dynamic Programming', 'C'] | 0 |
concatenated-words | ✔️ | C++ | TRIE + DFS | Easy Solution | c-trie-dfs-easy-solution-by-code_alone-vl56 | Approach\n Use Trie Data Structure and do dfs to find the count of words that are used to make the current word\n\n# Complexity\n- Time complexity:\n- O(N^ | code_alone | NORMAL | 2023-01-27T05:06:07.950886+00:00 | 2023-01-27T05:06:07.950929+00:00 | 780 | false | # Approach\n Use Trie Data Structure and do dfs to find the count of words that are used to make the current word\n\n# Complexity\n- Time complexity:\n- O(N^2)\n\n- Space complexity:\n- O(26*N)\n# Code\n```\n\nstruct Node{\n bool end = false;\n Node* next[26] = { NULL };\n};\n\nclass Solution {\npublic:\n ... | 3 | 0 | ['Trie', 'C++'] | 1 |
concatenated-words | Easy C++ recursive code 864 ms . | easy-c-recursive-code-864-ms-by-akt617-blfn | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. Simple approach with take | akt617 | NORMAL | 2023-01-27T04:31:21.365725+00:00 | 2023-01-27T04:31:21.365763+00:00 | 175 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->Simple approach with take and not take method.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(n)\n\n- Space complexity:\n<!-... | 3 | 0 | ['C++'] | 0 |
concatenated-words | Clean & Optimized Code + Commented | clean-optimized-code-commented-by-nextth-du0g | \nclass Solution {\npublic:\n bool check(string word, unordered_set<string>& dict, unordered_map<string, bool> &ump){\n if(ump.find(word) != ump.end | NextThread | NORMAL | 2023-01-27T04:29:17.675922+00:00 | 2023-01-27T04:29:17.675973+00:00 | 47 | false | ```\nclass Solution {\npublic:\n bool check(string word, unordered_set<string>& dict, unordered_map<string, bool> &ump){\n if(ump.find(word) != ump.end()) return ump[word];\n for(int i = 1 ; i < word.size() ; ++i) {\n string substring = word.substr(0, i); // check for every substring\n ... | 3 | 0 | ['C', 'Ordered Set'] | 0 |
concatenated-words | 📌📌 C++ || DFS || Hashset || Faster || Easy To Understand | c-dfs-hashset-faster-easy-to-understand-yk49q | Using DFS && Hashset\n\n Time Complexity :- O(N * L * L)\n\n Space Complexity :- O(N * L), Where L is the size of the string\n\n\nclass Solution {\npublic:\n | __KR_SHANU_IITG | NORMAL | 2023-01-27T02:51:17.292938+00:00 | 2023-01-27T02:51:17.292983+00:00 | 231 | false | * ***Using DFS && Hashset***\n\n* ***Time Complexity :- O(N * L * L)***\n\n* ***Space Complexity :- O(N * L), Where L is the size of the string***\n\n```\nclass Solution {\npublic:\n \n // set will store all the words of words\n \n unordered_set<string> s;\n \n bool helper(string& str, int i, int n)\n... | 3 | 0 | ['Depth-First Search', 'C', 'C++'] | 0 |
concatenated-words | Go - Easy to understand O(n**2) Approach✅ | go-easy-to-understand-on2-approach-by-si-37pw | Complexity\n- Time complexity: O(n^2*m)\n Add your time complexity here, e.g. O(n) \n\n# Code\n\nfunc findAllConcatenatedWordsInADict(words []string) []string { | sinistersup2001 | NORMAL | 2023-01-27T02:17:50.875045+00:00 | 2023-01-27T02:17:50.875078+00:00 | 997 | false | # Complexity\n- Time complexity: O(n^2*m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc findAllConcatenatedWordsInADict(words []string) []string {\n s := make(map[string]bool)\n concatenateWords := []string{}\n for _, word := range words {\n s[word] = true\n }\n for _... | 3 | 0 | ['Go'] | 0 |
concatenated-words | python3 | sort and use trie. | python3-sort-and-use-trie-by-iter_next-rdv1 | If there is word whose substrings are already in array, the length of each substring would be <= len(word) itself. Here is the logic below. \n1. Sort the array | iter_next | NORMAL | 2023-01-27T02:16:38.526434+00:00 | 2023-01-27T02:16:38.526462+00:00 | 1,177 | false | If there is word whose substrings are already in array, the length of each substring would be <= len(word) itself. Here is the logic below. \n1. Sort the array based on length of word.\n2. Identify if trie contains already a list of words that make up the word we are looking for using recursion. \n3. If (2) is true, ad... | 3 | 0 | ['Trie', 'Recursion', 'Python3'] | 1 |
concatenated-words | Python Short Brute Force 85% Time | python-short-brute-force-85-time-by-8by8-n872 | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n # Check if current word can be made from smaller wo | 8by8 | NORMAL | 2023-01-27T02:13:57.984953+00:00 | 2023-01-27T02:13:57.984981+00:00 | 681 | false | ```\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n # Check if current word can be made from smaller words\n def check(word):\n if word in s:\n return True\n # If prefix is seen, recurse on rest of word\n ret... | 3 | 0 | ['Recursion', 'Python', 'Python3'] | 2 |
concatenated-words | [Python] Straightforward brute-force solution without memoization/trie/DFS/BFS | python-straightforward-brute-force-solut-fga4 | A simple brute-force solution without memoization works for me. The algorithm is straightforward:\n1. Construct a dictionary/hashmap of words to enable O(1) loo | ardulat | NORMAL | 2023-01-27T01:50:01.143796+00:00 | 2023-01-27T01:50:01.143832+00:00 | 481 | false | A simple brute-force solution without memoization works for me. The algorithm is straightforward:\n1. Construct a dictionary/hashmap of words to enable O(1) lookup.\n2. For each word, check if the given word is concatenated:\n - Start with an empty subword\n - For each character `word[i]` in the given word, appen... | 3 | 0 | ['Recursion', 'Python'] | 1 |
numbers-with-repeated-digits | Solution | solution-by-deleted_user-ejr2 | C++ []\nclass Solution {\npublic:\n int numDupDigitsAtMostN(int n) {\n vector<int> digits{};\n int temp = n + 1;\n while (temp > 0) {\n | deleted_user | NORMAL | 2023-05-20T07:50:23.316211+00:00 | 2023-05-20T08:23:12.211778+00:00 | 5,239 | false | ```C++ []\nclass Solution {\npublic:\n int numDupDigitsAtMostN(int n) {\n vector<int> digits{};\n int temp = n + 1;\n while (temp > 0) {\n digits.emplace_back(temp % 10);\n temp /= 10;\n }\n int result = 0;\n int len = digits.size();\n int curr =... | 442 | 0 | ['C++', 'Java', 'Python3'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.