id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n\n int findPartitionPossible(int index, string str, unordered_map<string, int> &dict, vector<int> &dp){\n\n if(index == str.length()){\n return 1;\n }\n\n if(dp[index] == -1){\n\n for(int i = index; i < str.length(); i++){\n\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool solve(string s,unordered_map<string,int>&dict,unordered_map<string,int>&dp){\n if(s.length()==0) return true;\n if(dp.find(s)!=dp.end()) return dp[s];\n for(int len=1;len<=s.length();len++){\n string temp=s.substr(0,len);\n if(d... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\nint dp[302][302];\nbool solve(string& s,map<string,bool>& mp,int i,int j){\n if(j==s.size()){\n if(i==j)\n return 1;\n else\n return 0;\n }\n if(dp[i][j]!=-1)\n return dp[i][j];\n string p=s.substr(i,j-i+1);\n if(mp[p]==1){\n r... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\nint dp[302][302];\nbool solve(string& s,map<string,bool>& mp,int i,int j){\n if(j==s.size()){ // can also be done by backtracking\n if(i==j)\n return 1;\n else\n return 0;\n }\n if(dp[i][j]!=-1)\n return ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool wordBreak(string& s, vector<string>& wordDict) {\n unordered_map<string, bool> mp;\n\n for(auto i : wordDict) \n mp[i] = true;\n\n vector<vector<int>> dp(s.size()+1, vector<int> (s.size()+1, -1));\n\n return helper(s, 0, 0, mp, dp);... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool wordBreak(string& s, vector<string>& wordDict) {\n unordered_map<string, bool> mp;\n\n for(auto i : wordDict) \n mp[i] = true;\n\n vector<vector<int>> dp(s.size()+1, vector<int> (s.size()+1, -1));\n\n return helper(s, 0, 0, mp, dp);... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n \n bool check(string s, set<string> &st, map<string,bool> &mp){\n int n=s.length();\n \n if(n==0) return true;\n \n if(mp.find(s)!=mp.end()) return mp[s];\n \n for(int i=0;i<s.length();i++){\n string pre=s.substr(... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,bool> mp;\n bool solve(string s,unordered_set<string> st){\n if(s==\"\" || st.find(s)!=st.end()){\n return true;\n }\n\n if(mp.find(s)!=mp.end()){\n return mp[s];\n }\n\n for(int i=0;i<s.size();i... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> wordSet(wordDict.begin(), wordDict.end());\n unordered_map<string, bool> M;\n return helper(s, wordSet, M);\n }\n\nprivate:\n bool helper(string s, unordered_set<string>& w... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool rec(int index,string s, unordered_set<string> dict,vector<int> &dp)\n {\n if(index>=s.size())\n return true;\n \n if(dp[index]!=-1)\n return dp[index];\n for(int i=index;i<s.size();i++)\n {\n string c... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, bool>dp;\n\n bool solve(string s, unordered_map<string, int>& mp) {\n if(s.size() == 0) return true;\n\n if(dp.count(s)) return dp[s];\n\n bool ans = false;\n for(int i=0; i<s.size(); i++) {\n string left = s.sub... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,int>mp2;\n bool solve(string s,unordered_map<string,int>&mp){\n if(mp.find(s)!=mp.end()){\n return true;\n }\n if(mp2.find(s)!=mp.end()){\n return mp2[s];\n }\n for(int i=0;i<s.size();i++){\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool getsol(string s,unordered_set<string>st,int index,int n,vector<int>&dp){\n if(index==n){\n return 1;\n }\n string temp;\n if(dp[index]!=-1)\n return dp[index];\n for(int i=index;i<n;i++)\n {\n temp=te... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class TrieNode {\npublic:\n TrieNode *child[26];\n bool isWord;\n char ch;\n TrieNode() {\n isWord = false;\n for (auto &a : child) a = NULL;\n }\n};\nclass Solution {\npublic:\n TrieNode* root;\n void insert(string word) {\n TrieNode* temp = root;\n for(aut... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\n bool help(string s,unordered_set<string> st,int ind,vector<int> &dp){\n if(ind>=s.length())return true; \n if(dp[ind]!=-1){\n return dp[ind];\n }\n bool ans = false;\n for(int i = ind;i<s.length();i++){\n string temp = s.substr(... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string, int> memo;\n bool dfs(string s, unordered_set<string> set) {\n int n = s.length();\n if(n == 0)return true;\n if(memo.find(s) != memo.end())return memo[s];\n for(int j=1; j<=n; ++j) {\n string sub = s.substr(0, j... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n map<string,int> mp;\n int n;\n vector<int> t;\n bool helper(string &s, int i)\n {\n if(i>=n) return(t[i]=true);\n if(mp.find(s)!=mp.end()) return(t[i]=true);\n if(t[i]!=-1) return(t[i]);\n for(int l=1;l<n;l++)\n {\n st... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Node {\npublic:\n char ch;\n Node* children[26];\n bool isEnd;\n\n Node(char x = '/') { // Default constructor for root node\n this->ch = x;\n this->isEnd = false;\n for (int i = 0; i < 26; i++) {\n this->children[i] = NULL;\n }\n }\n};\n\nclass ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n\n int dp[305][305];\n\n bool solve(int cur_index, int last_index, map <string, int>& freq, string& s) {\n int n = s.size();\n\n if (cur_index == n && last_index == n-1) {\n\n // cout << \"TRUEEEEE!!!\" << endl;\n\n return true;\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool solve(string s,vector<string> dict,int ind,unordered_map<string,bool> mpp,vector<int> &dp){\n if(ind==s.size()){\n return true;\n }\n if(dp[ind]!=-1){\n return dp[ind];\n }\n string str=\"\";\n bool ans=fals... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\nprivate:\n bool solve(int ind,string &s,int n,unordered_map<string,int> m,vector<int>&dp){\n if(ind == n){\n return true;\n }\n\n if(dp[ind] != -1) return dp[ind];\n\n for(int i=1;i <= n-ind;i++){\n string temp=s.substr(ind,i);\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> wordSet(wordDict.begin(), wordDict.end()); // store\n vector<bool> dp(s.size() + 1, false);\n dp[0] = true;\n \n for (int i = 1; i <= s.size(); i++) {\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\nbool word(vector<string> &v, int nv, string s, int ns, string temp)\n{\n if (temp.size() > ns)\n {\n return false;\n }\n if (temp == s)\n {\n return true;\n }\n bool ans = false;\n for (int i = 0; i < nv; i++)\n {\n ans = (ans || wo... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool solve(string &S,map<string,int> &mp,int s,int e,int n,vector<vector<int>> &dp){\n string str=S.substr(s,e-s+1);\n if(e==n) return mp[str];\n if(dp[s][e]!=-1) return dp[s][e];\n if(!mp[str]) return dp[s][n]=solve(S,mp,s,e+1,n,dp);\n else... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n map<string,bool> dict;\n string str;\n int n;\n int dp[301][301];\n bool rec(int prev, int curr)\n {\n string s = str.substr(prev,curr-prev+1);\n bool ans = 0;\n if(curr == n)\n {\n if(prev == n)\n {\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool helper(string s, set<string>st,int j,map<pair<string,int>,bool>&dp) {\n string temp=\"\";\n if(j == s.size())\n return true;\n for(int i = j ; i < s.size();i++){\n temp.push_back(s[i]);\n if(st.find(temp) != st.end())... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "/*\n\nfind prefix s(i)\n-> no words with prefix in dict : i++\n-> yes prefix : add words w prefix\n--> iterate over words w the prefix to find match\n---> i++ -> prefix still valid : repeat\n---> if word -> save it \n---> else -> not valid \n\n-> delete valid words from string and repeat for remaining stri... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,bool> dict;\n string str;\n int n;\n int dp[301][301];\n bool rec(int prev, int curr)\n {\n string s = str.substr(prev,curr-prev+1);\n bool ans = 0;\n if(curr == n)\n {\n if(prev == n)\n {\n... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n //unordered_map of the wordDict\n unordered_map<string,bool> dict;\n for(int i=0;i<wordDict.size();i++){\n dict[wordDict[i]] = true;\n }\n int size = s.length();\n vect... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\n bool helper(string s, int si, unordered_map<string, int> mpp, vector<int>& dp){\n if(si == s.size()){\n return true;\n }\n if(dp[si]!=-1){\n return dp[si];\n }\n for(int i=si; i<s.size(); i++){\n if(mpp.count(s.substr... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\nprivate:\n bool calculate(string& s, int index, int currLength, string temp, unordered_map<string, int>& wordMap, vector<vector<int>>& dp) {\n if(index >= s.length()) return currLength == s.length();\n if(dp[index][currLength] != -1) return dp[index][currLength];\n ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,int> word_dict;\n int solve(string s, unordered_map<string, int> st,int start,vector<int> &dp)\n {\n int l=s.length();\n if(start == s.length())\n return 1;\n if(dp[start]!=-1)\n return dp[start];\n\n\n int ... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "\n\nclass Solution {\npublic:\n unordered_map<int, bool> dp;\n bool wordhelper(string s, int ind, unordered_map<string, bool>& worldmap) {\n if(s == \"\") {\n return true;\n }\n if(dp.count(ind)) {\n return dp[ind];\n }\n int size = s.size();\... |
139 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p>
<p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta... | 3 | {
"code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n vector<bool> ans(s.length()+1, false);\n unordered_map<string, int> mp;\n for(auto x: wordDict){\n mp[x]++;\n }\n ans[0] = true;\n for(int i = 1; i <= s.length(); i++){... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n bool acceptance(unsigned int i, unsigned int j)\n {\n for (const auto& letter : words[j])\n {\n if (letter != letters[i])\n return false;\n ++i;\n }\n return true;\n }\n void search(unsigned int i)\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\n void f(unordered_set<string> &dict, int start, string &curr, string &s, vector<string> &ans){\n if (start == s.size()){\n curr.pop_back();\n ans.push_back(curr);\n return;\n }\n\n string temp = \"\";\n for (int i = start;i<s... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n vector<string> ans;\n struct Node{\n Node* list[26];\n bool isWord;\n Node(){\n for(int i=0;i<26;i++)list[i] = 0;\n isWord = false;\n }\n };\n\n void insert_word(Node* root, string &word){\n Node* cur = root;\n... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string_view> word_set;\n for (const string& word : wordDict) {\n word_set.insert(word);\n }\n\n vector<str... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n void solve(string &s, unordered_map<string,int>&mp,vector<string>&ans,string str, int idx){\n //base case\n if(idx == s.size()){\n str.pop_back();\n ans.push_back(str);\n return;\n }\n\n string ptr = \"\";\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n // Map to store results of subproblems\n unordered_map<int, vector<string>> dp;\n\n // Iterate from the end of the string to the beginning\n for (int startIdx = s.size(); startIdx >= ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class TrieNode {\npublic:\n bool isEnd;\n TrieNode* children[26];\n\n TrieNode() {\n isEnd = false;\n for (int i = 0; i < 26; i++) {\n children[i] = nullptr;\n }\n }\n};\n\nclass Trie {\npublic:\n TrieNode* root;\n\n Trie() { root = new TrieNode(); }\n\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n struct QueueItem {\n int head;\n std::string string;\n };\n\n void wordBreakRec(\n std::string_view s,\n const std::vector<std::string>& word_dict,\n std::string cur,\n std::vector<std::string>& result\n ) {\n if(s == ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n vector<string> ans;\n\n void f(int i,string temp,string &s,set<string> &dict){\n if(i>=s.size()){\n temp.pop_back();\n ans.push_back(temp);\n return;\n }\n\n string t=\"\";\n\n for(int k=i;k<s.size();k++){\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 0 | {
"code": "class Solution {\npublic:\n void solve(string s, vector<string>& res, vector<string>& temp,\n unordered_set<string>& st) {\n // base case\n if(s.length()==0){\n string s;\n for(auto x: temp){\n s+=x + \" \";\n }\n s.p... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 1 | {
"code": "class Solution {\npublic:\n set<string>dict;\n void func(vector<string>&out, string s, int st,string ans) {\n string temp = \"\";\n if (st==s.size()) {\n \n out.push_back(ans.substr(1));\n return;\n }\n for (int j=st;j<s.size();j++) {\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 1 | {
"code": "class Solution {\npublic:\n vector<string> result;\n unordered_set<string> dict;\n\n void solve(int i, string& currSentence, string &s) {\n if(i >= s.length()) {\n result.push_back(currSentence);\n return;\n }\n\n for(int j = i; j < s.length(); j++) {\n\n... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 1 | {
"code": "class Solution {\npublic:\n vector<string> v;\n vector<string> current;\n class TrieNode{\n public:\n bool isWord;\n TrieNode* children[26];\n TrieNode(){\n isWord = false;\n for(int i = 0;i<26;++i) children[i] = NULL;\n }\n void inse... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 1 | {
"code": "class Solution {\npublic:\n set<string> dict;\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n for(auto x : wordDict)dict.insert(x);\n vector<string> res;\n rec(s, 0, \"\", res);\n return res;\n }\n\n void rec(string s, int beg, string curr, vector<... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 1 | {
"code": "class Solution {\npublic:\n set<string> dict;\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n for(auto x : wordDict)dict.insert(x);\n vector<string> res;\n rec(s, 0, \"\", res);\n return res;\n }\n\n void rec(string s, int beg, string curr, vector<... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 1 | {
"code": "class Solution {\npublic:\n vector<string>res;\n void solve(int index,string temp,string s,unordered_map<string,int>&mp){\n if(index==s.size()){\n temp.pop_back();\n res.push_back(temp);\n return;\n }\n string t=\"\";\n for(int i=index;i<s.... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 2 | {
"code": "\nclass Solution\n{\nprivate:\n vector<string> res;\n struct Node\n {\n unordered_map<char, Node *> next;\n bool endNode;\n Node() : endNode(false) {}\n };\n\n struct Try\n {\n Node *root;\n Try() : root(new Node()) {}\n } tr;\n\n void insertString... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\n public:\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> wordSet{wordDict.begin(), wordDict.end()};\n unordered_map<string, vector<string>> mem;\n return wordBreak(s, wordSet, mem);\n }\n\n private:\n vector<string> wordBreak(const stri... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> set;\n vector<string> res;\n for(auto word:wordDict)\n set.insert(word);\n \n string curr=\"\";\n findHelper(0,s,curr,set,res);\n r... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> set;\n vector<string> res;\n for(auto word:wordDict)\n set.insert(word);\n \n string curr=\"\";\n findHelper(0,s,curr,set,res);\n r... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n int count(string one){\n int res=0;\n for(auto c : one){\n if(c==' ') continue;\n res++;\n }\n return res;\n }\n void doit(string s, unordered_set<string> dict, int start, string one, vector<string>& res){\n if(st... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\n unordered_map<string, bool> m;\n unordered_map<string, vector<string>> bre;\n\n vector<string> util(string s){\n if(bre[s].size()) return bre[s];\n vector<string> ans;\n string t = \"\";\n int l = s.length();\n for(int i = 0; i < l; i++){\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int,vector<string>>dp;\n vector<string> findAns(string s,unordered_map<string,bool>&isValid,int index){\n if(index==s.length()){\n return {\"\"};\n }\n if(dp.find(index)!=dp.end()){\n return dp[index];\n }\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n bool findWords(string& s, unordered_map<string,bool>& dict,int start, int curr,vector<vector<int>>& dp,string currResult, vector<string>& result){\n\n string currWord = s.substr(start,curr-start+1);\n if(curr==s.length()-1){\n if(dict.find(currWord)!=... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n vector<string> wordBreak(string s, vector<string> wordDict) {\n unordered_set<string> wordDict_set(wordDict.begin(), wordDict.end());\n unordered_map<string, vector<string>> memo;\n return DFS(s, wordDict_set, memo);\n}\n\nvector<string> DFS(string s, unordered_set<s... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n \n bool wordind(vector<string> dic, string pre){\n \n for(int i=0;i<dic.size();i++){\n if(dic[i]==pre)\n return true;\n }\n return false;\n \n }\n \n void findword(vector<string> dic, vector<string> &res... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\n string s;\n vector<string> ans;\n set<string> words;\npublic:\n void rec(int i,int j, string str){\n if(j == s.size()){\n \n if(i == j){\n ans.push_back(str);\n }\n return;\n }\n string curr = s.su... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n void f(int start,int curr,string &s,set<string> &word,vector<string> &ans,string t){\n if(curr==s.size()){\n if(word.find(s.substr(start,curr-start+1))!=word.end()){\n t+=s.substr(start,curr-start+1);\n ans.push_back(t);\n ... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n vector<string> ans;\n void rec(string cur, string target, unordered_map<string, bool> dict, int i)\n {\n if(i==target.size())\n {\n cur.pop_back();\n ans.push_back(cur);\n return;\n }\n\n string nextWord = \"\... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n void solve(int idx, string &s, set<string> st, vector<string> &result, string temp){\n if(idx == s.length()){\n temp.pop_back();\n result.push_back(temp);\n return;\n }\n\n string substr = \"\";\n for(int i=idx; i<s... |
140 | <p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, add spaces in <code>s</code> to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in <strong>any order</strong>.</p>
<p><strong>Note</strong> that the same word in the dictionary may be... | 3 | {
"code": "class Solution {\npublic:\n vector<string> wordBreak(string s, vector<string>& wordDict) {\n int n=s.size();\n int m=wordDict.size();\n vector<string> ret;\n vector<bool> matched(m,true);\n string str=\"\";\n sol(s,wordDict,0,str,matched,0,ret); \n ... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": " static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, k_str; getline(cin, str) && getline(cin, k_str); cout << '\\n') {\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "// static const auto speedup = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cou... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": " static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, k_str; getline(cin, str) && getline(cin, k_str); cout << '\\n') {\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
61 | <p>Given the <code>head</code> of a linked list, rotate the list to the right by <code>k</code> places.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px; height: 191px;" />
<pre>
<strong>Input:</st... | 0 | {
"code": "class Solution {\npublic:\n ListNode* rotateRight(ListNode* head, int k) {\n // base cases\n if (head == NULL) return NULL;\n if (head->next == NULL) return head;\n // close the linked list into the ring\n ListNode* old_tail = head;\n int n;\n for (n = 1;... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\n double factorial(int num,int n){\n if(num==n||num==0){\n return 1;\n }\n return num*factorial(num-1,n);\n }\npublic:\n int uniquePaths(int m, int n) {\n int maxi=max(m-1,n-1);\n int mini=min(m-1,n-1);\n return int(factorial(m+... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int ncr(int n, int r) {\n double res = 1;\n for(int i=1; i<=r; i++) {\n res = res * (n-r+i)/i;\n }\n return (int)res;\n }\n\n int uniquePaths(int m, int n) {\n return ncr(m-1+n-1, n-1);\n }\n};",
"memory": "7200"
} |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n \n //1st solution recusion gives TLE\n\n // int solve(int i, int j, int m, int n)\n // {\n // if(i==m-1 && j==n-1)\n // {\n // return 1;\n // }\n // if(i>=m || j>=n)\n // {\n // return 0;\n // }\n // ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int NCR(int n, int r) {\n if (r == 0)\n return 1;\n\n if (r > n / 2)\n return NCR(n, n - r);\n\n long res = 1;\n\n for (int k = 1; k <= r; ++k) {\n res *= n - k + 1;\n res /= k;\n }\n\n retu... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int solve(int x, int y, int m, int n, vector<vector<int>> &dp){\n if(x==m-1 && y==n-1){\n return 1;\n }\n if(dp[x][y]!=-1) return dp[x][y];\n int down=0;\n int right=0;\n\n if(x+1<m){\n down=solve(x+1, y, m, n, ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution{\n public:\n int uniquePaths(int m, int n){\n int M[m][n];\n for(int i = 0; i<m; i++){\n M[i][0] = 1;\n }\n for(int i = 0; i<n; i++){\n M[0][i] = 1;\n }\n for(int i = 1; i < m ; i++){\n for(int j = 1; j<n; j++){... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n int M[m][n];\n \n for(int i=0;i<m;i++)\n {\n M[i][0]=1;\n }\n for(int j=0;j<n;j++)\n {\n M[0][j]=1;\n }\n for(int i =1;i<m;i++){\n for(int j... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n int Matrix[m][n];\n \n for(int i=0;i<m;i++)\n Matrix[i][0]=1;\n for(int j=0;j<n;j++)\n Matrix[0][j]=1;\n for(int i=1;i<m;i++){\n for(int j=1;j<n;j++){\n Matrix[i][j]=M... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int NCR(int n, int r) {\n if (r == 0)\n return 1;\n\n /*\n Extra computation saving for large R,\n using property:\n N choose R = N choose (N-R)\n */\n if (r > n / 2)\n return NCR(n, n - r);\n\n ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n vector<int> dp(n,1); // first line just can right so all 1\n \n // check each line expect first \n for(int i=1 ; i<m;i++){\n for(int j=1;j<n;j++){\n // update dp[j] = leftside dp[j] + upsi... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n std::vector<int>aboveRow(n,1);\n\n for(int row=1;row<m;row++){\n std::vector<int>currentRow(n,1);\n for(int col=1;col<n;col++){\n currentRow[col]=currentRow[col-1]+aboveRow[col];\n ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n vector<int> prev(n, 0);\n for(int i = 0; i < m; i++) {\n vector<int> temp(n, 0);\n for(int j = 0; j < n; j++) {\n if(i == 0 && j == 0) {\n temp[j] = 1;\n } e... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 0 | {
"code": "class Solution {\npublic:\n int topdown(int n,int m,vector<vector<int>> &dp){\n if(n==0&&m==0) return 1;\n if(n<0||m<0) return 0;\n\n if(dp[n][m]!=-1) return dp[n][m];\n\n int left = topdown(n,m-1,dp);\n int up = topdown(n-1,m,dp);\n\n return dp[n][m] = left + ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 1 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n \n vector<vector<int>> dp(m, vector<int>(n, 0));\n\n \n for (int i = 0; i < m; i++) {\n dp[i][0] = 1;\n }\n for (int j = 0; j < n; j++) {\n dp[0][j] = 1;\n }\n\n \n f... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 1 | {
"code": "class Solution {\npublic:\n \n int ans=0;\n int solve(int m,int n,int i,int j, vector<vector<int>>& dp){\n if(i==m-1) return 1;\n if(j==n-1) return 1;\n if(dp[i][j]!=-1) return dp[i][j];\n dp[i][j]=solve(m,n,i+1,j,dp)+solve(m,n,i,j+1,dp);\n return dp[i][j];\n ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 1 | {
"code": "class Solution {\npublic:\n\n int helper(int i, int j, int m, int n, vector<vector<int>> &dp){\n\n //base case\n if(i == m or j == n) return 0;\n\n if(i == m-1 and j== n-1) return 1;\n\n //check cache\n if(dp[i][j] != -1) return dp[i][j];\n\n //try all ways\n ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 1 | {
"code": "class Solution {\npublic:\nint solve(int i,int j,vector<vector<int>>& dp){\n if(i==0 && j == 0){\n return 1;\n }\n if(i < 0 || j < 0){\n return 0;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n\n int up = solve(i-1,j,dp);\n int left = solve(i,j-1,dp);\n\n ... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 1 | {
"code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n vector<vector<int>>v(m,vector<int>(n,-1));\n int dx[]={0,1};\n int dy[]={1,0};\n for(int i=0;i<m;i++)\n {\n v[i][n-1]=1;\n }\n for(int i=0;i<n;i++)\n {\n v[m-1][i]=... |
62 | <p>There is a robot on an <code>m x n</code> grid. The robot is initially located at the <strong>top-left corner</strong> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or right at any poin... | 1 | {
"code": "class Solution {\npublic:\n int f(int n, int m, int i, int j, vector<vector<int>> &dp){\n if(i>=n||j>=m) return 0;\n if(i==n-1&&j==m-1) return 1;\n if(dp[i][j]!=-1) return dp[i][j];\n int d=f(n,m,i,j+1,dp);\n int r=f(n,m,i+1,j,dp);\n return dp[i][j]=d+r;\n }\... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& g) {\n int r = g.size(), c = g[0].size();\n if(g[r-1][c-1] == 1) return 0;\n for(int i = r-1; i>=0; i--){\n for(int j = c-1; j >= 0; j--){\n if(g[i][j] == 1){\n ... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n int n = obstacleGrid.size(), m = obstacleGrid.front().size();\n\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < m; j++)\n {\n if (obstacleGrid... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n int m = obstacleGrid.size();\n int n = obstacleGrid[0].size();\n obstacleGrid[0][0] = (obstacleGrid[0][0] == 1) ? 0 : -1;\n for (int i = 0; i < m; i++) {\n for (int j = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.