id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie{\npublic:\n int flag;\n unordered_map<char, Trie*>child;\n // vector<Trie*>child;\n Trie(){\n flag = -1;\n }\n};\nclass Solution {\npublic:\n static bool vec_sort(string& a, string& b){\n return a.length() < b.length();\n }\n void go(Trie* node, Trie* root, ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie{\npublic:\n int flag;\n unordered_map<char, Trie*>child;\n Trie(){\n flag = -1;\n }\n};\nclass Solution {\npublic:\n void go(Trie* node, Trie* root, string& s, int spot, vector<string>& ans, int depth){\n if(node->child.count(s[spot]) == 0){\n if(depth != ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct node {\n\n bool is_end;\n\n unordered_map<char, node*> mp;\n\n node(): is_end(false) {}\n};\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& arr) {\n \n vector<string> res;\n \n node* root = new node();\n\n s... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class TrieNode {\npublic:\n bool isEnd;\n unordered_map<char, TrieNode*> children;\n \n TrieNode() : isEnd(false) {}\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n \n Trie() {\n root = new TrieNode();\n }\n \n void insert(const string& word) {\n TrieNode* node ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct TrieNode{\n TrieNode(bool word = false)\n {\n isWord = word;\n }\n\n unordered_map<char, TrieNode*> children;\n bool isWord;\n};\n\nclass Trie{\n private:\n TrieNode* root;\n\n void addWord(string word)\n {\n TrieNode* node = root;\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n class TrieNode{\n public:\n unordered_map<char ,TrieNode*> mp;\n bool end;\n TrieNode (){\n end=false;\n }\n };\n\n class Trie{\n public:\n TrieNode * trie;\n int cnt;\n Trie(){\n trie=... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n class TrieNode{\n public:\n unordered_map<char ,TrieNode*> mp;\n bool end;\n TrieNode (){\n end=false;\n }\n };\n\n class Trie{\n public:\n TrieNode * trie;\n int cnt;\n Trie(){\n trie=... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n bool tell(string& curwrd,set<string>& st,int indx,string tillnow,map<pair<string,int>,bool>& mp)\n {\n int n=curwrd.size();\n if(indx==n)\n {\n if(st.find(tillnow)!=st.end()||tillnow==\"\")\n return true;\n return f... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, bool> memo;\n\n bool concatWord(const string& w, const unordered_set<string>& dict) {\n auto it = memo.find(w);\n if (it != memo.end())\n return memo[w];\n\n for (int i = 1; i < w.size(); ++i) {\n string pref... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct Node{\n Node* ch[26];\n bool end;\n};\nclass Trie{\npublic:\n Node* root;\n Trie(){\n root= new Node();\n }\n void insert(string s){\n Node* temp= root;\n for(auto c: s){\n int t= c-'a';\n if(temp->ch[t]==NULL) temp->ch[t]= new Node();\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\nprivate:\n struct TrieNode {\n TrieNode* children[26];\n bool isEnd;\n TrieNode() : isEnd(false) {\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n }\n };\n\n TrieNode* root;\n\n void insert(const ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie {\n Trie *arr[26];\n bool end = false;\n\n public:\n Trie() {\n for (int i = 0; i < 26; i++)\n arr[i] = nullptr;\n }\n\n void insert(const string &s, Trie *t) {\n for (const char &c : s) {\n const int k = c - 'a';\n if (t->arr[k] == ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie {\n Trie *arr[26];\n bool end = false;\n\n public:\n Trie() {\n for (int i = 0; i < 26; i++)\n arr[i] = nullptr;\n }\n\n void insert(const string &s, Trie *t) {\n for (const char &c : s) {\n const int k = c - 'a';\n if (t->arr[k] == ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n struct Node{\n bool end;\n Node *nxt[26];\n Node(){\n end = false;\n memset(nxt, 0, sizeof nxt);\n }\n }*root;\n void insert(string &s){\n Node *cur = root;\n for(int i =0; i < s.size(); i++){\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie {\n public:\n Trie() noexcept = default;\n\n void add(const string& s) {\n Trie* current = this;\n for(const auto c : s) {\n auto& ptr = current->get(c);\n if(!ptr) {\n ptr = std::make_unique<Trie>();\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct Trie\n{\n std::array<Trie*, 26> _childs;\n bool isWord = false;\n\n Trie * emplace(string & w, int i)\n {\n if(i == w.size())\n {\n isWord = true;\n return this;\n }\n else\n {\n int j = w[i]-'a';\n if(!_child... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "\nclass Solution {\n public:\n class Tire {\n struct TireNode {\n bool has = false;\n unique_ptr<TireNode> child[26] = {};\n };\n\n unique_ptr<TireNode> root;\n\n public:\n Tire() : root(std::make_unique<TireNode>()) {}\n\n unordered_map<str... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n string findkey(string &s, int k){\n string key = \"\";\n string tmp = to_string(k);\n key+=tmp;\n key.push_back('#');\n for(char x : s){\n key.push_back(x);\n }\n return key;\n }\n bool solve(string &s, int i, ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct Node{\n Node* child[26];\n bool eow;\n\n Node(){\n for(int i = 0; i < 26; i++){\n child[i] = NULL;\n }\n eow = false;\n }\n};\n\nclass Solution {\npublic:\n Node* root;\n\n Solution() {\n root = new Node();\n }\n\n void insert(string s) ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "typedef long long ll;\nconst int MOD1 = 1e9 + 7;\nconst int MOD2 = 1e9 + 9;\nconst int st1 = 137;\nconst int st2 = 2137;\nclass Solution {\npublic:\n pair<int, int> hash(string &s, int a, int b){\n int hash1=0, hash2=0;\n for(int i=a;i<=b;i++){\n hash1=((ll)hash1*st1+s[i])%MOD1;... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "\nclass Solution {\npublic:\n\n map<string,int> wordMap;\n \n struct TrieNode{\n TrieNode* children[26];\n bool isLeaf;\n\n TrieNode(){\n for(int i = 0; i < 26 ; i++){\n children[i] = NULL;\n }\n isLeaf = false;\n }\n };\n\n void insert(Tri... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class TrieNode{\n public:\n TrieNode* node[26];\n bool ends;\n TrieNode(){\n ends = 0;\n for(int i = 0; i < 26; i++){\n node[i] = nullptr;\n }\n }\n\n};\nclass Trie{\n public:\n TrieNode* root;\n Trie(){\n root =... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class trie{\n public:\n trie *children[26];\n bool end;\n\n \n trie(){\n this->end=false;\n for(int i=0;i<26;i++) this->children[i]=NULL;\n }\n void insert(string &key){\n trie *root=this;\n for(auto i:key){\n if(root->children[i-'a']==NULL){\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Node {\npublic:\n bool isEnd = false;\n Node *next[26] = {nullptr};\n};\n\nclass Trie {\npublic:\n Node *head;\n\n Trie() {\n head = new Node();\n }\n\n void insert(string word) {\n Node *tmp = head;\n for (auto c: word) {\n c -= 'a';\n if ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct node{\n node* links[26];\n bool flag=false;\n\n bool contains(char ch){\n return links[ch-'a']!=NULL;\n }\n\n void put(char ch,node* temp){\n links[ch-'a']=temp;\n }\n\n node* get(char ch){\n return links[ch-'a'];\n }\n\n void setflag(){\n this-... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "const int INF = 1e9;\n\nstruct TrieNode {\n TrieNode* next[26];\n bool terminal = false;\n\n TrieNode() {\n for (auto& v : next)\n v = nullptr;\n }\n};\n\nstruct Trie {\n TrieNode* root;\n\n Trie() : root(new TrieNode) {}\n\n void insert(string s) {\n TrieNode* v = root;\n \n for (ch... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n string substring(string s,int i,int j){\n string temp;\n for(int k=i;k<j;k++)\n temp.push_back(s[k]);\n return temp;\n }\n bool solve(int i,int j,string &s,vector<vector<int>>&dp,map<string,int> &m){\n if(i==s.size()){\n string ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n bool func(int i, string& s, string dum, map<string, int>& m, int flag, map<pair<int, string>, int>& dp) {\n if (i == s.length()) {\n return dum.empty() && flag >= 2;\n }\n\n if (dp.find({i, dum}) != dp.end()) return dp[{i, dum}];\n \n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class TrieNode {\npublic:\n vector<TrieNode*> children;\n int path = 0;\n int end = 0;\n\n TrieNode(){\n children.assign(26,nullptr);\n }\n};\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n auto root = new TrieNode();\... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trienode{\n public:\n bool end=false;\n Trienode* *next =new Trienode* [26];\n Trienode(){\n for(int i=0 ; i<26 ;i++){\n this->next[i]=NULL;\n }\n }\n};\nclass Trie{\n public:\n Trienode * root=new Trienode;\n void insert(Trienode * root,string word){\... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct TrieNode {\n bool isWord = false;\n TrieNode* children[26];\n unordered_map<string, bool> cache;\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n }\n void insert(string& s) {\n TrieNode* head = this;\n for (auto i... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "struct TrieNode {\n bool isWord = false;\n TrieNode* children[26];\n unordered_map<string, bool> cache;\n TrieNode() {\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n }\n void insert(string& s) {\n TrieNode* head = this;\n for (auto i... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class TrieNode {\npublic:\n char c;\n vector<TrieNode*> children;\n bool end;\n\n // Constructor\n TrieNode(char k) : c(k), children(26, nullptr), end(false) {}\n};\n\nclass Solution {\npublic :\n TrieNode*root;\n Solution(){\n root = new TrieNode('N');\n }\n void insert(T... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie{\n public:\n vector<Trie*> children = vector<Trie*>(26, nullptr);\n bool flag = 0;\n};\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n vector<string> res;\n Trie* root = new Trie();\n for(auto& el: words)\n... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n\n struct Node{\n char ch;\n int isWord;\n vector<Node*> next;\n Node(char c){\n ch = c;\n isWord = 0;\n next.resize(26);\n for(int i=0;i<26;i++){\n next[i] = nullptr;\n }\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Trie{\npublic:\n Trie* children[26];\n bool whether_end;\n Trie():whether_end(false){\n fill(begin(children), end(children), nullptr);\n }\n};\nclass Solution {\nprivate:\n Trie * t;\n vector<string>res;\n void add_word(string & word){\n Trie * cur=t;\n for(c... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n struct TrieNode {\n int chars[32] = {};\n bool contains = false;\n };\n\n std::vector<std::string> findAllConcatenatedWordsInADict(std::vector<std::string>& words) {\n std::vector<TrieNode> nodes(1);\n for (auto const& word : words) {\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n struct TrieNode {\n int chars[32] = {};\n bool contains = false;\n };\n\n std::vector<std::string> findAllConcatenatedWordsInADict(std::vector<std::string>& words) {\n std::vector<TrieNode> nodes(1);\n for (auto const& word : words) {\n ... |
472 | <p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words (not ne... | 3 | {
"code": "class Solution {\npublic:\n struct TrieNode {\n int chars[31] = {};\n bool contains = false;\n };\n\n std::vector<std::string> findAllConcatenatedWordsInADict(std::vector<std::string>& words) {\n std::vector<TrieNode> nodes(1);\n for (auto const& word : words) {\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 0 | {
"code": "class Solution {\npublic:\n bool backtrack(vector<int>& matchsticks, vector<int>&ans, int index, int side){\n if(index==matchsticks.size()) return true;\n for(int i=0;i<4;i++){\n if(ans[i]+matchsticks[index]<=side){\n ans[i]+=matchsticks[index];\n i... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 0 | {
"code": "class Solution {\npublic:\n bool solve(vector<int>& matchsticks, int idx, int n, vector<int>& sides) {\n if (idx == n) return true;\n bool ans = false;\n int a = matchsticks[idx];\n for(int i = 0; i < 4; i++) {\n if (sides[i] >= a) {\n sides[i] -= a;... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n void helper(vector<int>& matchsticks, int target, int start, int cur_mask, unordered_set<int>& valid) {\n if (target == 0) {\n valid.insert(cur_mask);\n if (cur_mask == 0)\n cout << target << \" \" << start << \" \" << cur_mask << e... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& v) {\n \n int tot = accumulate(begin(v) , end(v) , 0);\n \n if(tot%4 or v.size() < 4)return 0;\n \n vector<int>poss;\n \n int n = v.size();\n \n vector<int>ids(n);\n iota... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool helper(int sum, int bitmask, int tar, int cnt, vector<int>& matchsticks, vector<int>& dp) {\n if (cnt == 4) {\n return true;\n }\n if (dp[bitmask] != -1) {\n return dp[bitmask];\n }\n if (sum == tar) {\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool solve(std::vector<int> &matchsticks, int n, int k, int curSum, int mask, int target, std::vector<int> &dpTable) {\n if (mask == (1 << n) - 1) return true;\n\n if (dpTable[mask] != -1) return dpTable[mask];\n\n bool result = false;\n for (int n... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& nums) {\n if (nums.empty() || nums.size() < 4) return false;\n int sum = accumulate(nums.begin(), nums.end(), 0);\n if (sum % 4 != 0) return false;\n int n = nums.size(), all = (1 << n) - 1, target = sum / 4;\n v... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\nbool makesquare(vector<int>& nums) {\nif (nums.empty() || nums.size() < 4) return false;\nint sum = accumulate(nums.begin(), nums.end(), 0);\nif (sum % 4 != 0) return false;\nint n = nums.size(), all = (1 << n) - 1, target = sum / 4;\nvector<int> masks, validHalf(1 << n, false);\... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n bool rec(int submask , vector<int> & matchsticks , int req){\n int n = matchsticks.size();\n if(submask == (1 << n) - 1){\n return true;\n }\n if(dp[submask] != -1){\n return dp[submask];\n }\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "// class Solution {\n// public:\n// bool helper(vector<int>& matchsticks , vector<int> &sides , int index , int val){\n// if(index==matchsticks.size()){\n// return true;\n// }\n// for(int i=0 ; i<4 ; i++){\n// if(sides[i] + matchsticks[index] <= val){\n//... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "\n// //tle\n// class Solution {\n// public:\n// bool f(int i,vector<int> &d, int side, vector<int>& stick){\n// if(i==stick.size() && (d[0] == d[1] && d[1] == d[2] && d[2] == d[3])) return true;\n// if(i==stick.size()) return false;\n\n// for(int j=0;j<4;j++){ ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int, bool> memo; \n int target; \n \n bool dp(vector<int>& nums, int mask, int currentSum, int sides) {\n if (sides == 4) return true; \n if (memo.count(mask)) return memo[mask]; \n \n for (int i = 0; i < ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int n = matchsticks.size();\n int sum = 0;\n for (int m : matchsticks) sum += m;\n if (sum % 4) return false;\n int target = sum / 4;\n unordered_set<int> memo;\n function<bool(int,... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int sum = accumulate(matchsticks.begin(), matchsticks.end(), 0);\n if(sum % 4) return false;\n int side = sum / 4;\n\n \n vector<unordered_set<unsigned long>> memo(4);\n\n function<bool(bi... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\n map<pair<int,int>,bool> dp;\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int n=matchsticks.size();\n if(n<4) return 0;\n\n int sum=0;\n for(int i=0;i<n;i++)\n {\n sum+=matchsticks[i];\n }\n\n if(sum%4) return 0... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\n map<pair<int,int>,bool> dp;\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int n=matchsticks.size();\n if(n<4) return 0;\n\n int sum=0;\n for(int i=0;i<n;i++)\n {\n sum+=matchsticks[i];\n }\n\n if(sum%4) return 0... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n int side;\n vector<int> dp;\n bool solve(vector<int> &a, int k, int curr, int mask, int i){\n if(k == 1) return true;\n if(i>=a.size()) return false;\n\n if(dp[mask] != -1) return false;\n\n if(curr == side) return dp[mask] = solve(a, k-1, 0,... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int n=matchsticks.size();\n int sum=0;\n for(auto it:matchsticks){\n sum+=it;\n }\n if(sum%4!=0)return false;\n int target=sum/4;\n vector<pair<int,int>>dp(1<<n,{1e9,1e9}... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n long totalLength = 0;\n for(int &len : matchsticks){\n totalLength += len;\n }\n if(totalLength%4 != 0) return false;\n\n int sideLength = totalLength/4;\n long state = 0;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n long totalLength = 0;\n for(int &len : matchsticks){\n totalLength += len;\n }\n if(totalLength%4 != 0) return false;\n\n int sideLength = totalLength/4;\n long state = 0;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\n unordered_map<string, int> mp;\n int sl = 0;\n\npublic:\n bool makesquare(vector<int>& m) {\n int totalLength = accumulate(m.begin(), m.end(), 0);\n if (totalLength % 4 != 0) return false;\n sl = totalLength / 4;\n sort(m.rbegin(), m.rend());\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n // bool solve(int i, int n, int sum, int target, int k, vector<int>&v, vector<int>&vis) {\n // if (k == 0) return true;\n // if (sum == target) return solve(0, n, 0, target, k - 1, v, vis);\n\n // for (int j = i; j < n; ++j) {\n // if (vis[j] &... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matc) {\n sort(matc.begin(), matc.end(), greater<int>()); \n int summ = 0;\n for (int i = 0; i < matc.size(); i++) {\n summ += matc[i];\n }\n if (summ % 4 != 0)\n return false;\n\n i... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<int> nums,vector<bool>& visited,int currsum,int idx,int subsetsum,int k){\n if(k==0)return true;\n if(currsum>subsetsum)return false;\n if(currsum==subsetsum){\n return solve(nums,visited,0,0,subsetsum,k-1);\n }\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, bool> map; \n bool makesquare(vector<int>& matchsticks) {\n int sum = accumulate(matchsticks.begin(), matchsticks.end(), 0);\n if (sum % 4 != 0) return false;\n int target = sum / 4; \n //vector<bool> used(matchsticks.size(... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n bool helper(int index, int curr_k, int k, int currSum, int targetSum, string &picked, vector<int> &matchsticks, unordered_map<string, bool> &dp) {\n if(curr_k == k - 1) {\n return true;\n }\n if(currSum > targetSum) {\n return fals... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "const int SIDES = 4;\nconst int MAX_LENGTH = 15;\nint SIZE;\nint SIDE_SIZE;\n\n\nclass Solution {\npublic:\n bool dfs(const std::vector<int>& xs, std::bitset<MAX_LENGTH> mask, int side, int c, std::unordered_map<int, bool>& memo)\n { \n\n if(c == 4)\n return true;\n\n if(sid... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<int> &arr,int n,int k,vector<int> ref,\n int ind,int s){\n //base case:\n if(ind==n){\n for(int i=1;i<=k;i++){\n if(ref[i]!=s){\n return false;\n }\n }\n retur... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n typedef vector<int> I;\n int target;\n\n bool bt(I m, I s, int idx) {\n if (idx == m.size()) {\n for (int i : s) {\n if (i != target) {\n return false;\n }\n }\n return true;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n typedef vector<int> I;\n int target;\n\n bool bt(I m, I s, int idx) {\n if (idx == m.size()) {\n for (int i : s) {\n if (i != target) {\n return false;\n }\n }\n return true;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n string getState(int s1,int s2,int s3,int s4){\n vector<int> arr = {s1,s2,s3,s4};\n sort(arr.begin(),arr.end());\n string state=\"\";\n for(int i:arr){\n state+=to_string(i)+\":\";\n }\n return state;\n }\n bool dfs(in... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& A) {\n long sideSum = accumulate(A.begin(), A.end(), 0L);\n int n = A.size();\n \n // Check if the total length can be evenly divided into 4 sides\n if (sideSum % 4 != 0 || *max_element(A.begin(), A.end()) > side... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int solve(int cur,int idx,int mask,vector<int>&arr,int n,int l){\n if(idx==4) return true;\n if(dp[idx][mask]!=-1) return dp[idx][mask];\n bool ans = false;\n for(int i = 0; i < n; i++){\n if((mask&(1<<i))==0)... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\n vector<vector<int>> dp;\n bool check(int side, vector<int>& m, int mask, int curr, int count) {\n if (count == 4) {\n return true;\n }\n\n if (dp[count][mask] != -1) {\n return dp[count][mask];\n }\n\n bool ans = false;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int n = matchsticks.size();\n int tot = 0;\n vector<int>sum(1<<n);\n vector<int>dp(1<<n,-69);\n dp[0] = 0;\n for(int nxt: matchsticks){\n tot+=nxt;\n }\n if(tot%4 ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool func(int ind, vector<int>& side, vector<int> matchsticks){\n if(ind==matchsticks.size()){\n if(side[1]==side[2] && side[2]==side[3] && side[3]==side[4] && side[4]==sum/4) return true;\n return false;\n }\n \n if(side[1]>s... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n \n bool isPossible(vector<int> matchsticks, int target,vector<int> &res, int idx){\n \n if(idx == matchsticks.size()){\n return (res[0] == res[1] && res[1] == res[2] && res[2] == res[3]);\n }\n \n for(int i=0;i<4;i++){\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n \n bool dfs(vector<int> matchsticks, int target, vector<int> &sides, int idx){\n \n // base case\n if(idx == matchsticks.size()){\n if(sides[0] == sides[1] && sides[1] == sides[2] && sides[2] == sides[3]){\n return true;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\n using ll = int;\n using Key = tuple<ll, ll, ll, ll>; \n\n template<int i>\n Key update(Key k, int val){\n get<i>(k) += val;\n return k;\n }\n\n set<Key> genSet(int a, const vector<int>& sticks){\n set<Key> s;\n s.insert({0,0,0,0});\n f... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool makesquare(vector<int>& matchsticks) {\n int len = 0;\n int sum = 0;\n sort(matchsticks.begin(), matchsticks.end(), greater<int>());\n for(int& stick: matchsticks)\n {\n sum += stick;\n }\n len = sum / 4;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n int target;\n bool rec(int s, int mask, vector<int>& matchsticks, int sum, vector<vector<int>>& dp) {\n if (s == 4 and (mask == (1 << matchsticks.size()) - 1)) return true;\n if (sum > target) return false;\n if (sum == target) return rec(s+1, mask, ma... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n int lim;\n bool makesquare(vector<int>ms,vector<int>&dir,int n,int i){\n \n if(i == n){\n return true;\n }\n\n for(int j=0;j<4;j++){\n if(ms[i]+dir[j] <= lim){\n dir[j]+=ms[i];\n if(makesquare(... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "\n\n\n\n\nclass Solution {\npublic:\n bool Try(vector<int> matchsticks,int value,vector<int>& canh,int pos){\n if(pos==matchsticks.size()){\n return canh[0]==value&&canh[1]==value&&canh[2]==value&&canh[3]==value;\n }\n for(int i=0;i<4;++i){\n if(canh[i]+matchst... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n int n;\n int target;\n unordered_map<int, unordered_map<int, bool>> dp;\n\n bool makesquare(vector<int>& matchsticks) {\n n = matchsticks.size();\n if (n < 4) return false;\n\n int sum = std::accumulate(begin(matchsticks), end(matchsticks), 0);\n... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n bool rec(int i,vector<int> &nums,int k,vector<int> &v,int s)\n {\n int n=nums.size();\n if(i==n)\n {\n for(int j=0;j<k;j++)\n if(v[j]!=v[0]) return false;\n return true;\n }\n bool ans=false;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n bool solve(vector<int> nums, int index, int target, vector<int> sides){\n if(index == nums.size()) return true;\n for(int j = 0; j < 4; j++){\n if(sides[j] + nums[index] <= target){\n sides[j] += nums[index];\n if(solve... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n bool solve(vector<int> nums, int index, int target, vector<int> sides, int n){\n if(index == n) return true;\n for(int j = 0; j < 4; j++){\n if(sides[j] + nums[index] <= target){\n sides[j] += nums[index];\n if(solve(nu... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool backtrack(vector<int> arr,vector<int> m,int idx,int target){\n if(idx==-1) return true;\n \n for(int i=0;i<4;i++){\n \n if(arr[i]+m[idx]<=target){\n arr[i]+=m[idx];\n if(backtrack(arr,m,idx-1,target... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n bool solve(int bits,int sum, int num,vector<int>& a,int req,unordered_map<int,int>& dp) {\n int n = a.size();\n if(bits==0) {\n //cout<<sum<<\" \"<<num<<\"\\n\";\n return sum==req and num==4;\n }\n if(dp.find(bits)!=dp.end()... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n int n = 0;\n int side = 0;\n set<vector<int> > dp[20];\n\n bool isSquarePossible(vector<int> m, int x, int a, int b, int c, int d) {\n if (x==n) {\n if (a==side && b==side && c==side && d==side)\n return true;\n return false;... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n struct SetHash {\n std::size_t operator()(const std::set<int>& s) const {\n std::size_t hash = 0;\n for (const int& i : s) {\n hash ^= std::hash<int>{}(i) + 0x9e3779b9 + (hash << 6) + (hash >> 2);\n }\n return ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>>dp;\n bool solve(vector<int>&nums, int k, int currSum,int mask,int target)\n { \n if(k<0 || currSum<0)return false;\n if(currSum == 0)\n { \n return solve(nums,k-1,target,mask,target);\n }\n if(mask == (1<<nu... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\n vector<vector<int>> dp = vector<vector<int>> (3, vector<int>(1024 * 32, -1));\n\n bool topdown(int xi, int used, vector<int>& matchsticks, int target) {\n if (xi == 3)\n return true;\n\n if (dp[xi][used] != -1)\n return dp[xi][used] == 1;\n\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n map<vector<int>, bool> memo;\n bool helper(vector<int>& matchsticks, int a, int b, int c, int d, int res, int i) {\n vector<int> temp = {a, b, c, d};\n sort(temp.begin(), temp.end());\n\n if (i == matchsticks.size()) {\n if (a == b && b == c... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\nmap<pair<int,int>,bool> ma;\nint s=0;\nint format(vector<int> mat){\n int k =1;\n for(int i=0;i<mat.size();i++){\n k=k<<1;\n k = k|(mat[i]!=0);\n }\n // cout<<k<<\" \";\n return k;\n}\nbool cal(int k,vector<int> &mat,int c){\n // cout<<\"\\n\";\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\nmap<pair<int,int>,bool> ma;\nint s=0;\nint format(vector<int> mat){\n int k =1;\n for(int i=0;i<mat.size();i++){\n k=k<<1;\n k = k|(mat[i]!=0);\n }\n // cout<<k<<\" \";\n return k;\n}\nbool cal(int k,vector<int> &mat,int c){\n // cout<<\"\\n\";\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>matchsticks,int sum, int target, int k, vector<int> &visited, int mask, vector<int> &dp) {\n if(k==0) {\n bool ans = 1;\n for(auto x : visited) {\n ans = ans & x;\n }\n return ans;\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool solve(int mask, vector<int>& matchsticks, int index, int sum, int targetSum, vector<int> powerOf2, vector<int> &dp){\n if(sum > targetSum){\n return dp[mask] = false;\n }\n if(index == matchsticks.size()){\n return sum == target... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool f(vector<int>& a, int pos, long long c1, long long c2, long long c3, long long c4, long long s, unordered_map<int, int>& b) {\n if (pos < 0) {\n return c1 == c2 && c2 == c3 && c3 == c4;\n }\n if (c1 > s | c2 > s | c3 > s | c4 > s) {\n ... |
473 | <p>You are given an integer array <code>matchsticks</code> where <code>matchsticks[i]</code> is the length of the <code>i<sup>th</sup></code> matchstick. You want to use <strong>all the matchsticks</strong> to make one square. You <strong>should not break</strong> any stick, but you can link them up, and each matchstic... | 3 | {
"code": "class Solution {\npublic:\n bool f(vector<int>& a, int pos, long long c1, long long c2, long long c3, long long c4, long long s, unordered_map<int, int>& b) {\n if (pos < 0) {\n return c1 == c2 && c2 == c3 && c3 == c4;\n }\n if (c1 > s | c2 > s | c3 > s | c4 > s) {\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 0 | {
"code": "class Solution {\n int dp[101][101];\n int cnt[601][2];\n\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int sz = strs.size();\n \n for (int i = 0; i < sz; i++)\n for (char c : strs[i])\n cnt[i][c - '0']++;\n\n dp[cnt[0][1]]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.