id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<string, set<string>> mp;\n vector<vector<string>> suggestedProducts(vector<string>& products,\n string searchWord) {\n for (int i = 0; i < products.size(); i++) {\n string word = products[i];\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Solution {\npublic:\n\n class TrieNode {\n public:\n TrieNode() {\n for (int i = 0; i < 26; ++i) {\n children[i] = nullptr;\n }\n suggestions = vector<string>();\n }\n array<shared_ptr<TrieNode>, 26> children;\n vector<... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products,\n string searchWord) {\n // We can create a map of strings / substrings that point to a list of\n // words with our key as the prefix. e.g. WordMap['A'... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "struct Node {\n Node* links[26];\n int cntEndWith = 0;\n int cntPrefix = 0;\n vector<string> temp; \n bool containsKey(char ch) {\n return (links[ch - 'a'] != NULL); \n }\n Node* get(char ch) {\n return links[ch - 'a']; \n }\n void put(char ch, Node* node) {\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Trie {\npublic:\n char val;\n unordered_map<char, Trie*> children;\n\n priority_queue<string> words3;\n Trie(char val_): val(val_) {}\n Trie(char val_, priority_queue<string> words3_): val(val_), words3(words3_) {}\n};\nclass Solution {\npublic:\n vector<vector<string>> suggestedPro... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Node{\n public:\n char ch;\n unordered_map <char, Node*> mp;\n vector <string> words;\n bool terminal;\n\n public:\n Node(char ch, string word, bool terminal=false){\n this->ch = ch;\n this->terminal = terminal;\n this->words =... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Solution {\npublic:\n class Trie {\n public:\n Trie() {\n parent_ = nullptr;\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n }\n Trie(const std::string& prefix, Trie* parent) {\n prefix_ = prefix;\... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> suggested_products;\n\n sort(products.begin(), products.end());\n for(int i = 0; i < searchWord.length(); i++) {\n auto typed_str =... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n std::sort(products.begin(), products.end());\n vector<vector<string>> listofList;\n std::string searchString = \"\";\n for(int i = 0; i < searchWord.size(); i... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct Trie {\n Trie *next[128];\n bool end;\n Trie(){\n for(int i=0;i<128;i++){\n next[i]=NULL;\n }\n end=false;\n }\n};\n\nclass Solution {\n void DFS(Trie *t, string &curr, set<string> &recs){\n if(recs.count(curr) || recs.size()>=3){\n re... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n map<string, vector<string>> mp;\n vector<vector<string>> ans;\n for(auto it : products){\n int n = it.size();\n string t;\n for(int ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\nvoid helper(vector<string>&products,string &sw, int i, vector<string>&temp)\n{\n priority_queue<string,vector<string>,greater<string>>pq;\n for(auto it: products)\n {\n if(it.size()<i+1)continue;\n int flag=0;\n for(int k=0;k<=i;k++)\n {\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products,\n string searchWord) {\n vector<vector<string>> result;\n\n for (int i = 0; i < searchWord.length(); i++) {\n vector<string> temp;\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n //key 값과 같거나 큰 값이 처음으로 나오는 위치 반환\n int bs_lowerbound(string typing, vector<string> products, int len){\n int l = 0, r = products.size();\n while(l < r){\n int m = l + (r - l)/2;\n //string cmp = products[m].substr(0, len);\n /... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n //key 값과 같거나 큰 값이 처음으로 나오는 위치 반환\n int bs_lowerbound(string typing, vector<string> products, int len){\n int l = 0, r = products.size();\n while(l < r){\n int m = l + (r - l)/2;\n //string cmp = products[m].substr(0, len);\n /... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\n vector<string> bs(vector<string> arr, string s){\n int n=arr.size(), m=s.size();\n int low=0, high=n-1;\n\n while(low<=high){\n int mid=low+(high-low)/2;\n\n if(s<=arr[mid]){\n high=mid-1;\n }\n else{\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n //key 값과 같거나 큰 값이 처음으로 나오는 위치 반환\n int bs_lowerbound(string typing, vector<string> products, int len){\n int l = 0, r = products.size();\n while(l < r){\n int m = l + (r - l)/2;\n string cmp = products[m].substr(0, len);\n //c... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n int n=products.size();\n sort(products.begin(),products.end());\n vector<vector<string>>ans;\n vector<string>temp;\n string curr=\"\";\n for(aut... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n int n=products.size();\n sort(products.begin(),products.end());\n vector<vector<string>>ans;\n vector<string>temp;\n string curr=\"\";\n for(auto c:... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n int n = products.size();\n sort(products.begin(), products.end());\n vector<vector<string>> ans;\n vector<string> temp;\n string curr = \"\";\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n cin.tie(nullptr);\n cout.tie(nullptr);\n ios::sync_with_stdio(false);\n \n int n = products.size(); \n sort(products.begin(), products.end());\n... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n cin.tie(nullptr);\n cout.tie(nullptr);\n ios::sync_with_stdio(false);\n \n int n = products.size(); \n sort(products.begin(), products.end());\n... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n // products sorted in lexicographical order\n //Start from 0th element of word search, keep adding next element after each iteration is done\n //get substring of pro... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n int binarySearch(string typing, vector<string> products, int len){\n int l = 0, r = products.size() - 1;\n int idx;\n\n while(l <= r){\n int m = l + (r - l)/2;\n string cmp = products[m].substr(0, len);\n if(cmp == typing)... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& pro, string se) {\n sort(pro.begin(),pro.end());\n vector<vector<string>>ans;\n\n string temp ;\n\n for(int i = 0;i<se.size();i++){\n temp+=se[i];\n vector<string>v;\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> results;\n sort(products.begin(), products.end());\n string prefix = \"\";\n\n for (char ch : searchWord) {\n prefix += ch;\... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(),products.end());\n vector<vector<string>> ans;\n string prefix=\"\";\n for(char c:searchWord){\n prefix+=c;\n vect... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(), products.end());\n string wrd = \"\";\n vector<vector<string>> ans;\n \n for(auto c : searchWord){\n vector<string> s... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) \n {\n sort(products.begin(), products.end()); //sort products to get elements in lexicographical order\n vector<vector<string>> res;\n \n string cur = \"\";\n... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n void givelexiluna(vector<string>v){\n vector<string> vec;\n \n\n }\n\n vector<vector<string>> suggestedProducts(vector<string>& pro, string s) {\n map<string,int>mp;\n sort(pro.begin(),pro.end());\n int n = s.size();\n for(auto ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n int n = products.size();\n vector<vector<string>> ans;\n vector<string> temp;\n string current=\"\";\n sort(products.begin(),products.end());\n\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(), products.end());\n \n vector<vector<string>> finalProducts{};\n \n int searchIndex = 0;\n string currentTerm = searchWord... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(), products.end());\n \n vector<vector<string>> finalProducts{};\n \n int searchIndex = 0;\n string currentTerm = searchWord... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(), products.end());\n \n vector<vector<string>> finalProducts{};\n \n for (int i = 1; i <= searchWord.size(); i++) {\n v... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\n struct TrieNode {\n std::array<TrieNode*, 26> children;\n bool wordEnd{false};\n\n TrieNode* getNode(char ch) {\n return children[ch - 'a'];\n }\n\n void addWord(const std::string& word, int pos = 0){\n if(pos == word.size()) {\... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class TrieNode\n{\npublic:\n TrieNode* children[26];\n bool is_word;\n TrieNode();\n void insert(const std::string& s);\n void traverse(const std::string& prefix, std::string cur, int& k, std::vector<std::string>& res);\n TrieNode* find(const std::string& s);\n};\n\nTrieNode::TrieNode()\n... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct trieNode {\n vector<trieNode*> data;\n bool endOfWord;\n trieNode() {\n endOfWord = false;\n data = vector<trieNode*> (26, nullptr);\n }\n};\n\nclass Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n ve... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& p, string s) {\n string sp ;\n vector<vector<string>>v(s.size()); \n for(int i = 0;i<s.size();i++){ \n sp+=s[i] ; \n for(int k = 0;k<p.size();... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n vector<vector<string>> ans;\n for(int i = 0; i < searchWord.length(); i++) {\n string substr = searchWord.substr(0, i+1);\n vector<string> to_sort;\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n \n class trienode{\n \n public:\n char data;\n trienode* children[26];\n bool isterminal;\n \n trienode(char a)\n {\n data=a;\n for(int i=0;i<26;i++)\n {\n children[i]=N... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "#define N ('z' - 'a' + 1)\nclass T {\npublic:\nbool leaf;\nT* child[N];\n T() {\n for (int i = 0; i < N; ++i)\n child[i] = 0;\n leaf = false;\n }\n void insert(string& w) {\n T* node = this;\n for (int i = 0; i < w.size(); ++i) {\n if (!node->child... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class TrieNode {\npublic:\n char value;\n TrieNode* children[26];\n bool isterminal;\n\n TrieNode(char val) {\n this->value = val;\n for (int i = 0; i < 26; i++) {\n children[i] = NULL;\n }\n isterminal = false;\n }\n};\n\nclass Solution {\npublic:\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "auto init = [](){\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\n\nclass Trie {\npublic:\n bool ed[50007];\n int child[26][50007], num;\n Trie() {\n memset(ed, 0, sizeof(ed));\n memset(child, 0, sizeof(child));\n num = 0;\n }\n \... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& prod, string sword) {\n vector<vector<string>> res;\n vector<string> tmp;\n int idx = 0, pre_idx = 0, str_size = 0;\n\n sort(prod.begin(),prod.end());\n for(int i = 0; i < sword.size()... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& prod, string sword) {\n vector<vector<string>> res;\n vector<string> tmp;\n int idx = 0, pre_idx = 0, str_size = 0;\n\n sort(prod.begin(),prod.end());\n for(int i = 0; i < sword.size()... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(),products.end());\n vector<vector<string>> ans;\n // int cnt=0;\n int prev=0;\n for(int cnt=1;cnt<=searchWord.size();cnt++){\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "auto init = [](){\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\n\nclass Trie {\npublic:\n bool ed[20007];\n int child[26][20007], num;\n Trie() {\n memset(ed, 0, sizeof(ed));\n memset(child, 0, sizeof(child));\n num = 0;\n }\n \... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n bool check(string& s1,string& s2,int i){\n // cout<<i<<\" \"<<s1.substr(0,min((int)s1.size(),i))<<\" \"<<s2.substr(0,i)<<endl;\n return s1.substr(0,min((int)s1.size(),i))>=s2.substr(0,i);\n }\n vector<vector<string>> suggestedProducts(vector<string>& produ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n Solution(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n bool check(string& s1,string& s2,int i){\n // cout<<i<<\" \"<<s1.substr(0,min((int)s1.size(),i))<<\" \"<<s2.substr(0,i)<<endl;\n return s1.substr(0,min((int)s1.s... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct node {\n node (char let) : l(let), isEnd(false) {}\n char l;\n bool isEnd;\n std::vector<node*> ptrs;\n};\n\nclass Solution {\npublic:\n Solution() {\n root = new node('\\0');\n }\n\n std::vector<std::vector<std::string>> suggestedProducts(std::vector<std::string>& produc... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct node {\n node (char let) : l(let), isEnd(false) {}\n char l;\n bool isEnd;\n std::vector<node*> ptrs;\n};\n\nclass Solution {\npublic:\n Solution() {\n root = new node('\\0');\n }\n\n std::vector<std::vector<std::string>> suggestedProducts(std::vector<std::string>& produc... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\n\nprivate:\n\nstruct LetterNode_st;\n\ntypedef struct ChildNode_st {\n struct ChildNode_st* next;\n struct LetterNode_st* child;\n} ChildNode;\n\ntypedef struct LetterNode_st {\n char letter;\n bool is_word;\n ChildNode* children;\n} LetterNode;\n\nLetterNode* mRoot;\n\nvoi... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n struct TrieNode {\n map<char, TrieNode*> children;\n bool isEndOfWord = false;\n };\n\n class Trie {\n public:\n TrieNode* root;\n \n Trie() {\n root = new TrieNode();\n }\n \n void insert(const strin... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class TrieNode {\npublic:\n char data;\n map<int, TrieNode*> children;\n bool isEnd;\n\n TrieNode() {\n data = '-';\n isEnd = false;\n }\n\n TrieNode(char c) {\n data = c;\n isEnd = false;\n }\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n\n Trie() {... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class TrieNode {\npublic:\n char data;\n map<int, TrieNode*> children;\n bool isEnd;\n\n TrieNode(): data('-'), isEnd(false) {};\n\n TrieNode(char c) {\n data = c;\n isEnd = false;\n }\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n\n Trie() {\n root = new Trie... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class TrieNode {\npublic:\n char data;\n map<int, TrieNode*> children;\n bool isEnd;\n TrieNode(): data('-'), isEnd(false) {};\n TrieNode(char c): data(c), isEnd(false) {};\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n Trie() : root(new TrieNode()) {};\n //function to insert word... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Trie{\npublic:\n std::map<char, Trie*> children;\n bool is_end = false;\n};\n\nclass Solution {\nprivate:\n const int max_nof_strs = 3;\n void get_trie_strs(Trie* node, string buf_str, vector<string>& dst_strs){\n if(dst_strs.size() >= max_nof_strs) return;\n\n if(node->is_e... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\n class TrieNode{\n public:\n map<char, TrieNode*> children;\n bool end;\n TrieNode(){\n end = false;\n }\n };\n TrieNode* root;\npublic:\n void addProducts(vector<string>& products){\n for(int i=0; i<products.size(); i++){\n... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct TrieNode {\n map<char, TrieNode*> m;\n bool isEnd = false;\n};\nclass Solution {\n TrieNode *root = new TrieNode();\npublic:\n void getThreeWord(string s, TrieNode *root, vector<string>&words){\n if (!root || words.size() == 3)\n return;\n\n if (root->isEnd)\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct TrieNode\n{\n map<char, TrieNode*> children;\n bool isEndOfWord;\n \n TrieNode() : isEndOfWord(false) {}\n};\n\nclass Trie\n{\nprivate:\n TrieNode *root;\n \n void findWordsWithPrefix(TrieNode* node, string currentWord, vector<string>& result) {\n // Nếu đã đủ 3 từ, ta dừ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct TrieNode{\n TrieNode* children[26];\n bool isTerminal = false;\n};\nclass Solution {\npublic:\n void insert(TrieNode* root,string n){\n for(int i = 0;i < n.size();i++){\n if(root->children[n[i] - 'a']){\n root = root->children[n[i] - 'a'];\n }\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct TrieNode{\n TrieNode* children[26];\n bool isTerminal = false;\n};\nclass Solution {\npublic:\n void insert(TrieNode* root,string n){\n for(int i = 0;i < n.size();i++){\n if(root->children[n[i] - 'a']){\n root = root->children[n[i] - 'a'];\n }\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\n vector<Solution*>child;\n Solution * head;\n bool is_end;\npublic:\n Solution()\n {\n child.resize(26);\n is_end = false;\n }\n void insert(string word)\n {\n if(head==NULL) head = new Solution();\n Solution * temp = head;\n for(... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class TrieNode {\npublic:\n explicit TrieNode(char v) : value(v) {\n\n }\n char value;\n map<char, TrieNode*> children;\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n Trie() {\n root = new TrieNode(1);\n }\n\n void build(const string& word) {\n TrieNode* curr = root;... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct Node {\n unique_ptr<Node> child[26];\n bool isTerminal;\n Node() : isTerminal(false) {}\n};\n\nclass Trie {\n unique_ptr<Node> root;\n\npublic:\n Trie() : root(make_unique<Node>()) {}\n\n void add(const string& word) {\n Node* temp = root.get();\n for (char c : word) ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "#include <cstddef>\n#include <iostream>\n#include <memory>\n#include <map>\n#include <optional>\n#include <string>\n#include <string_view>\n\n\nclass TrieNode\n{\nprivate:\n typedef std::map<char, std::unique_ptr<TrieNode>> children_t;\npublic:\n void insert(const std::string& word)\n {\n t... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "#include <algorithm>\n#include <cstddef>\n#include <iostream>\n#include <memory>\n#include <map>\n#include <optional>\n#include <string>\n#include <string_view>\n\n\nclass TrieNode\n{\nprivate:\n typedef std::map<char, std::unique_ptr<TrieNode>> children_t;\npublic:\n void insert(const std::string& w... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Node {\npublic:\n bool flag;\n Node* links[26] = {NULL};\n Node(){\n flag = false;\n }\n};\n\nclass Solution {\n void add_word(Node* root, string &word){\n Node* curr = root;\n for(auto it: word){\n int ch = it-'a';\n if(!curr->links[ch]) curr... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "// To find lexicographically smallest, do dfs for each character from 'a' till 'z'\n\nstruct TrieNode {\n unordered_map<int, TrieNode*> links;\n bool isEnd;\n\n TrieNode() {\n isEnd = 0;\n }\n\n bool containsKey(char ch) {\n return links[ch - 'a'];\n }\n\n void putKey(Tri... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class SolutionUsingBinarySearch {\npublic:\n vector<vector<string>> suggestedProducts(\n vector<string>& products,\n string searchWord) {\n vector<vector<string>> ret;\n \n sort(products.begin(), products.end());\n \n string q = \"\";\n for... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n bool startsWith(string prefix, string s) {\n if(prefix.length()>s.length()){\n return false;\n }\n\n return (s.substr(0, prefix.length())==prefix);\n }\n\n vector<string> getThreeOrLessStringsHavingPrefix(string prefix, vector<string>& p... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(),products.end());\n vector<vector<string>>ans;\n for(int i=0;i<searchWord.length();i++){\n vector<string>temp;\n int j=0;... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\n\npublic:\n // Solution* children[26];\n // bool isEnd;\n // Solution() {\n // for (int i = 0; i < 26; i++)\n // children[i] = NULL;\n // isEnd = false;\n // }\n // void insert(string word) {\n // Solution* curr = this;\n // for (char ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n //foreach product try matching startswith(searchWorld)\n //put into a minHeap of strings\n //pop top 3\n int n = searchWord.size();\n vector<vector<str... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n bool solve(string text,string prefix){\n return mismatch(prefix.begin(), prefix.end(), text.begin(), text.end()).first == prefix.end();\n }\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n //We can try to do brute... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\nprivate:\n struct Node {\n unordered_map<char, unique_ptr<Node>> children;\n bool isEnd;\n Node() : isEnd(false) {}\n };\n\n unique_ptr<Node> root;\n\n void insert(const string& word) {\n Node* node = root.get();\n for (char ch : word) {\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "struct Node {\n Node* links[26];\n bool flag = false;\n Node() {\n for (int i = 0; i < 26; i++) {\n links[i] = nullptr;\n }\n }\n};\n\nclass Trie {\npublic:\n Node* root;\n Trie() {\n root = new Node();\n }\n void insert(string s) {\n Node* nod... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n struct TreeNode {\n bool isWord;\n char letter;\n vector<TreeNode*> children;\n };\n\n TreeNode* getChildAt(char letter, TreeNode* node) {\n for (auto child : node->children) {\n if (child->letter == letter) {\n retu... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "\nclass Solution {\n public:\n class Tire {\n struct TireNode {\n string value;\n unique_ptr<TireNode> child[26] = {};\n };\n\n TireNode root;\n\n void InsertInternal(TireNode* root, const string& word, int i) {\n if (i == word.size()) {\n ... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {\n sort(products.begin(),products.end());\n vector<vector<string>> ans (searchWord.size());\n\n for(int i=0;i<searchWord.size();i++){\n for(string p:products... |
1,397 | <p>You are given an array of strings <code>products</code> and a string <code>searchWord</code>.</p>
<p>Design a system that suggests at most three product names from <code>products</code> after each character of <code>searchWord</code> is typed. Suggested products should have common prefix with <code>searchWord</code... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<string>> suggestedProducts(vector<string>& p, string w) {\n sort(p.begin(),p.end());\n int n=w.size();\n vector<vector<string>> ans(n);\n for(int i=1;i<=n;i++){\n for(auto x:p) if(x.substr(0,i)==w.substr(0,i)){\n ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 1 | {
"code": "class Solution {\npublic:\n #define mod 1000000007\n #define ll long long\n vector< vector<int> >dp;\n int helper(int n,int idx,int steps){\n if(steps==0){\n if(idx==0) return 1;\n else return 0;\n }\n if(dp[idx][steps]!=-1) return dp[idx][steps];\n ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 1 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7;\n int solve(int i, int steps, int arrLen, vector<vector<int>>& memo) {\n if (i < 0 || i >= arrLen) return 0;\n if (steps < 0) return 0;\n if (steps == 0) return i == 0 ? 1 : 0;\n\n if (memo[i][steps] != -1) return memo[i][steps]... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 1 | {
"code": "class Solution {\npublic:\n int numWays(int s, int n) {\n int mxm = min(n, s/2+1), mod= 1e9 + 7;\n vector dp(mxm, vector<int>(s+1, -1));\n \n function<int(int, int)> f = [&] (int index, int steps) -> int {\n if(steps == 0 && index == 0)return 1;\n if(ste... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 1 | {
"code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n int N = 1000000007;\n if (steps == 1 || arrLen == 1)\n return 1;\n vector<int> dp(min(steps + 1, arrLen));\n dp[0] = 1;\n for (int i = 0; i < steps; ++i) {\n vector<int> dp2(dp);\n... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 1 | {
"code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n int lens = min(steps+1, arrLen);\n vector<int> dp(lens);\n dp[0] = 1;\n int mod = 1000000007;\n for(int i = 0; i<steps; i++)\n {\n vector<int> nxt(lens);\n for(int j=0; j<mi... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 1 | {
"code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n const int mod = 1e9 + 7;\n arrLen = min(arrLen, steps);\n\n // dp[i] - no. of ways to reach at i after steps\n\n // dp[i][j] -> dp[i + 1][j - 1]\n // dp[i][j] -> dp[i][j]\n // dp[i][j] -> dp[i + ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\npublic:\n const int mod=1e9+7;\n vector<vector<long long>>dp;\n int solve(int &n,int tot,int i ){\n if(i>=n){\n return 0;\n }\n \n long long op2=0,op3=0;\n if(tot==0)return i==0;\n if(dp[i][tot]!=-1)return dp[i][tot];\n ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\npublic:\n long long mod=1e9+7;\n long long m;\n int solve(int ind,int steps,vector<vector<int>>&dp){\n\n if(ind==0 && steps==0){\n return 1;\n }\n if(ind<0 || ind>=m || steps==0 || ind>steps){\n return 0;\n }\n if(dp[ind][s... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\npublic:\n long long int mod = 1e9 + 7 ;\n long long int dp[1000][1000] ;\n long long int fxn(long long int i , long long int cnt , long long int steps , long long int arrLen){\n if(cnt == steps){\n if(i == 0) return 1 ;\n return 0 ;\n }\n ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n int recur(int n,int i,int s,vector<vector<int>>&dp){\n if(s==0){\n if(i==0)return 1;\n return 0;\n }\n if(dp[i][s]!=-1)return dp[i][s];\n int a=recur(n,i,s-1,dp);\n a%=mod;\n if(i<n-1){\n ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\npublic:\n int n;\n int MOD = 1e9+7;\n vector<vector<int>>dp;\n int F(int steps, int i){\n if(steps==0 && i==0) return 1;\n if(steps==0 || i==n || i==-1) return 0;\n if(dp[steps][i]!=-1) return dp[steps][i];\n int stay=0, left=0, right=0;\n st... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\n const static int MOD = 1e9 + 7;\npublic:\n int numWays(int steps, \n int arrLen // arrLen\n ) {\n\n int n = min(steps, arrLen);\n vector<long> dp(n + 2);\n dp[1] = 1;\n for(int i = 0;i<steps;i++) {\n vector<long> ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "class Solution {\npublic:\n \n // long long int solve(int steps, int arrLen,int i,vector<vector<long long int>> &dp)\n // {\n // if(i>=arrLen||i<0)\n // return 0;\n // if(steps==0)\n // {\n // if(i==0)\n // return 1;\n // return 0;\n ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 2 | {
"code": "\n// breakDown Hard to easy [recursion]\n// Trust on yourself - you are doing better 99% students \n\n// point-1 You have a pointer at index 0 in an array of size arrLen.\n// point-2 each steps, \n// you can move left by 1 position\n// you can move right by 1 position\n// you can stay into same position \n... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 3 | {
"code": "class Solution {\n static const int mod=1000000007;\n // int helper(int d,int s,int l,vector<vector<int>>&dp)\n // {\n // if(s==0)\n // {\n // if(d==0)\n // return 1;\n // return 0;\n // }\n // if(d>=l)\n // return 0;\n // ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 3 | {
"code": "class Solution {\npublic:\n#define MOD 1000000007\n int numWays(int steps, int arrLen) {\n int n = min(arrLen, steps)+5;\n vector<vector<long long>> dp(steps+1, vector<long long>(n));\n dp[0][0] = 1;\n\n for(int i = 1; i <= steps; i++){\n for(int j = 0; j < min(i, ... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 3 | {
"code": "class Solution {\n int mod=(int)(1e9+7);\n long long solve(long long i ,long long steps,long long arrlen,vector<vector<long long>>&dp){\n if(i<0 || i>=arrlen) return 0;\n\n if(steps==0){\n if(i==0) return 1;\n return 0;\n }\n\n if(dp[i][steps]... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 3 | {
"code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n vector<long long> curr(arrLen, 0);\n curr[0] = 1;\n for (int i = 0; i < steps; i++) {\n long long prev = 0;\n for (int j = 0; j < min(arrLen, steps-i+1); j++) {\n long long c = cu... |
1,398 | <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p>
<p>Given two integers <code>steps</code> and <c... | 3 | {
"code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n std::vector<unsigned int> cur(arrLen);\n std::vector<unsigned int> prev(arrLen);\n\n int modulo = 1e9 + 7;\n prev[0] = 1;\n for (int i = 1; i < steps + 1; ++i) {\n for (int j = 0; j < std::mi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.