id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n std::stack<string> st;\n std::stack<string> st2;\n\n for(int i = 1; i<path.size(); ++i){\n string s = \"\";\n while(i<path.size() && path[i]!='/'){\n s += path[i];\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "// #include <fmt/core.h>\n\nclass Solution {\npublic:\n\n void clear_double_dot (std::stack<std::string>& st) {\n int dd_count = 1;\n while (!st.empty() && st.top() == \"..\") {\n ++dd_count;\n st.pop();\n }\n std::cout << \"dd: \" << dd_count << '\\n';\...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n \n stack<string> st;\n string res;\n \n for(int i = 0; i<path.size(); ++i)\n {\n if(path[i] == '/') \n continue;\n string temp;\n\t\t\t// iterate till we do...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n vector<string> items;\n string curItem;\n for (char c : path) {\n if (c == '/') {\n if (!curItem.empty()){\n items.push_back(curItem);\n curItem.erase();\...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n vector<string> items;\n string curItem;\n for (char c : path) {\n if (c == '/') {\n if (!curItem.empty()){\n items.push_back(curItem);\n curItem.erase();\...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stack<string> st;\n int i=0;\n string s = \"\";\n if (path[path.size()-1] != '/') path += '/';\n while (i<path.size())\n {\n if (path[i] == '/')\n {\n while (i+...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
1
{ "code": "\t\t\t\t\t// \\U0001f609\\U0001f609\\U0001f609\\U0001f609Please upvote if it helps \\U0001f609\\U0001f609\\U0001f609\\U0001f609\nclass Solution {\npublic:\n string simplifyPath(string path) {\n \n stack<string> st;\n string res;\n \n for(int i = 0; i<path.size(); ++i)...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n void buildAns(stack<string> &s,string &ans){\n if(s.empty()) return;\n string minpath=s.top();s.pop();\n buildAns(s,ans);\n ans+=minpath;\n }\n string simplifyPath(string path) {\n stack<string>s;\n int i=0;\n while(i<p...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n \n void buildAns(stack<string>&s,string &ans){\n if(s.empty()){\n return;\n }\n string minPath=s.top(); s.pop();\n buildAns(s,ans);\n\n ans+=minPath;\n\n\n }\n string simplifyPath(string path) {\n stack<st...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "\nclass Solution {\npublic:\nvoid buildAns(stack<string>&s, string&ans) {\n if(s.empty()) {\n return;\n }\n string minPath = s.top(); s.pop();\n buildAns(s, ans);\n ans += minPath;\n}\n string simplifyPath(string path) {\n stack<string>s;\n int i= 0;\n while(i ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n // path += \"/\";\n // stack<string> st;\n // string curr;\n // for (int i = 0; i < path.size(); i++) {\n // if (path[i] != '/')\n // curr += path[i];\n // else {\n //...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n char delimeter='/';\n string ans=\"\";\n \n vector<string> tokens;\n vector<string> stack;\n stringstream ss(path);\n string token;\n \n while(getline(ss, token, delime...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n\n vector<string> SplitString(string &s) {\n vector<string> vec;\n \n int i = 0, j = 0;\n while(i < size(s)) {\n while(s[i] == '/') ++i;\n j = i;\n string w;\n while(j < size(s) && s[j] != '/') {\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n int n=path.length();\n stringstream ss(path);\n stack<string> st;\n string token=\"\";\n while(getline(ss,token,'/'))\n {\n //cout<<token<<\" \";\n if(token==\"\" || token==\"...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stack<string> s;\n int n = path.size();\n int i = 0;\n //cout << \"Length: \" << n << endl;\n while (i < n) {\n if (path[i] == '/') {\n i++;\n continue;\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n std::vector<std::string> tokens = tokenize(path, '/');\n std::stack<std::string> stack;\n\n for (const std::string& t : tokens) {\n if (t == \".\") continue; // ignore current directory\n else if ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n vector<string> split(string s, string d) {\n vector<string> ans;\n size_t start = 0, end = s.find(d);\n while(end != string::npos) {\n ans.push_back(s.substr(start, end-start));\n start = end+d.length();\n end = s.find(d, ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n void reverse(string& s) {\n int start = 0;\n int end = s.length() - 1;\n while (start < end) {\n char t = s[start];\n s[start] = s[end];\n s[end] = t;\n start++;\n end--;\n }\n }\n\n stri...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n string remove = \"\";\n vector<string> locations;\n\n for (int i = 0; i < path.length(); i ++){\n char letter = path[i];\n //cout << \"Letter: \" << letter << \"\\n\\n\";\n string word ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n \n stack<string> com;\n path = path+\"/\";\n stack<string> coms;\n char d = '/';\n int pos = path.find(d,1);\n int curr = 1;\n //input preprocessing\n while(pos != string::npos...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n \n stack<string> com;\n path = path+\"/\";\n stack<string> coms;\n char d = '/';\n int pos = path.find(d,1);\n int curr = 1;\n //input preprocessing\n while(pos != string::npos...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n \n stack<string> com;\n path = path+\"/\";\n stack<string> coms;\n char d = '/';\n int pos = path.find(d,1);\n int curr = 1;\n //input preprocessing\n while(pos != string::npos...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n \n stack<string> com;\n path = path+\"/\";\n stack<string> coms;\n char d = '/';\n int pos = path.find(d,1);\n int curr = 1;\n //input preprocessing\n while(pos != string::npos...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n vector<string> inp(0);\n string cur = \"\";\n\n for(int i = 0; i<path.length(); ++i)\n {\n if(path[i] == '/')\n {\n if(cur.length() != 0)inp.push_back(cur);\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n path += \"/\";\n stack<string> stc;\n string cur;\n for (int i = 0; i < path.size(); i++) {\n if (path[i] != '/')\n cur += path[i];\n else {\n if (cur != \"\" ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n path += \"/\";\n stack<string> stc;\n string cur;\n for (int i = 0; i < path.size(); i++) {\n if (path[i] != '/')\n cur += path[i];\n else {\n if (cur != \"\" ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stack<string> st;\n string temp=\"\";\n for(int i=1;i<path.size();i++)\n {\n if(path[i]=='/')\n {\n if(temp==\"..\")\n {\n if(!st.empty())\n...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n vector<string> inp(0);\n string cur = \"\";\n\n for(int i = 0; i<path.length(); ++i)\n {\n if(path[i] == '/')\n {\n if(cur.length() != 0)inp.push_back(cur);\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n vector<string>v;\n string res=\"\";\n for(int i=0;i<path.length();i++)\n {\n if(path[i]!='/')\n {\n res+=path[i];\n }\n else\n {\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string p) {\n vector<string> stack;\n stringstream ss(p);\n \n\n for(string line; getline(ss, line, '/');)\n {\n if(line == \"..\")\n {\n if(!stack.empty())\n {\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n int n=path.size();\n vector<string> sv;\n for(int i=1; i<n; i++)\n {\n string curr=\"\";\n while(i<n && path[i]!='/')\n {\n curr+=path[i];\n i++;\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stack<string> s;\n int i=0;\n while(i<path.length())\n { \n string temp;\n int j=i;\n while(path[j] != '/')\n {\n char x=path[j];\n tem...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stack<string> s;\n int i=0;\n while(i<path.length())\n { \n string temp;\n int j=i;\n while(path[j] != '/')\n {\n char x=path[j];\n tem...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stringstream ss(path);\n string token;\n stack<string> st;\n while(getline(ss, token, '/')) {\n if (token == \"\" || token == \".\") continue;\n if (token == \"..\") {\n if (...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stringstream ss(path);\n string token;\n stack<string> st;\n while(getline(ss, token, '/')) {\n if (token == \"\" || token == \".\") continue;\n if (token == \"..\") {\n if (...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stringstream ss(path);\n vector<string> vec;\n string t;\n while (getline(ss, t, '/')) {\n vec.push_back(t);\n }\n\n stack<string> stk;\n string res;\n for (int i = 0; i < ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution\n{\npublic:\n // spliting the string on delimiter\n vector<string> split(string s, char delimiter)\n {\n vector<string> res;\n stringstream ss(s);\n string token = \"\";\n while (getline(ss, token, delimiter))\n {\n res.push_back(token);...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stack<string> st;\n vector<string> components;\n string token;\n istringstream tokenStream(path);\n\n // Split the path by '/' delimiter\n while (getline(tokenStream, token, '/')) {\n co...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "\nclass Solution {\n public:\n vector<string> split(const string &str, char delimiter) {\n vector<string> tokens;\n stringstream ss(str);\n string token;\n\n while (getline(ss, token, delimiter)) {\n tokens.push_back(token);\n }\n\n return tokens;\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stringstream ss(path);\n string tok;\n deque<string> stk;\n while(getline(ss, tok, '/'))\n {\n if (tok == \"..\") {\n if (!stk.empty()) stk.pop_back();\n }\n ...
71
<p>You are given an <em>absolute</em> path for a Unix-style file system, which always begins with a slash <code>&#39;/&#39;</code>. Your task is to transform this absolute path into its <strong>simplified canonical path</strong>.</p> <p>The <em>rules</em> of a Unix-style file system are as follows:</p> <ul> <li>A si...
3
{ "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n stringstream ss(path);\n string tok;\n deque<string> stk;\n while(getline(ss, tok, '/'))\n {\n if (tok == \"..\") {\n if (!stk.empty()) stk.pop_back();\n }\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "template <typename Head0, typename Head1, typename... Tail>\nconstexpr auto min(const Head0 &head0, const Head1 &head1, const Tail &... tail)\n{\n if constexpr (sizeof...(tail) == 0) {\n return head0 < head1 ? head0 : head1;\n }\n else {\n return min(min(head0, head1), tail...);\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "constexpr int MAX_N = 5e2 + 5;\nconstinit int dp_i1[MAX_N]{};\nclass Solution {\npublic:\n int minDistance(string &word1, string &word2) {\n if (word1.size() < word2.size()) {\n std::swap(word1, word2);\n }\n int n = word1.size(), m = word2.size(), inf = 1e9;\n for...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "class Solution {\npublic:\n int minDistance(string S1, string S2) {\n int n = S1.size();\n int m = S2.size();\n\n // Create two arrays to store previous and current row of edit distances\n vector<int> prev(m + 1, 0);\n vector<int> cur(m + 1, 0);\n\n // Initialize the first row\n for (...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "#include <string>\n#include <algorithm>\n\nusing namespace std;\n\n// Using 1D Dynamic Programming [O(m*n), O(min(m,n))]\nclass Solution {\npublic:\n int minDistance(string word1, string word2) {\n int m = word1.size();\n int n = word2.size();\n\n // Ensure word2 is the shorter stri...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "class Solution {\npublic:\n int dp[505][505];\n \n int f(string &s1, string &s2, int i, int j) {\n // Base cases\n if (i == s1.size()) return s2.size() - j; // Remaining insertions to match s2\n if (j == s2.size()) return s1.size() - i; // Remaining deletions to match s1\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int m=word1.length(),n=word2.length();\n int dp[m+1][n+1];\n for(int i=0; i<=m; i++) dp[i][0]=i;\n for(int i=0; i<=n; i++) dp[0][i]=i;\n for(int i=1; i<=m; i++){\n for(int j=1; j<=n;...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int** cache = new int*[word1.size()+1];\n for (int i = 0; i < word1.size()+1; i++)\n cache[i] = new int[word2.size()+1];\n \n for (int i = 0; i < word1.size()+1; i++) {\n for (in...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
0
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int** cache = new int*[word1.size()+1];\n for (int i = 0; i < word1.size()+1; i++)\n cache[i] = new int[word2.size()+1];\n \n for (int i = 0; i < word1.size()+1; i++) {\n for (in...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
1
{ "code": "class Solution {\npublic:\n int solve(string &a, string &b,int i,int j,vector<vector<int>>&dp){\n if(i==a.length()){\n return b.length()-j;\n }\n if(j==b.length()){\n return a.length()-i;\n }\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n int ans...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
1
{ "code": "class Solution {\npublic:\n int find(int len1 , int len2 , string &word1, string &word2 , vector<vector<int>> &dp){\n\n if (len1 == 0) return len2; // Need to insert all characters of word2\n if (len2 == 0) return len1; // Need to delete all characters of word1\n\n if(dp[len1][len2]...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int n = word1.size() ; \n int m = word2.size() ; \n if(m == 0 && n ==0 )return 0 ; \n if(m == 0 || n == 0 )return 1; \n vector<vector<int>>dp(n + 5 , vector<int>(m + 5)) ; \n for...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int helper(int i,int j,string &word1,string &word2){\n int n1 = word1.size();\n int n2 = word2.size();\n if (dp[i][j]!=-1)return dp[i][j];\n if (i==n1 && j == n2){\n return 0;\n }\n if (i==n1){\n...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int solve(int i, int j, string &s, string &t, vector<vector<double>> &dp){\n if(i==0) return j;// as there are j+1 operations required to convert str1 to str2\n if(j==0) return i;// as str2 is exausted, i still have i+1 string still to be deleted\n \n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int m = word1.size();\n int n = word2.size();\n \n vector<vector<long long>> dp(m+1, vector<long long>(n+1, INT_MAX));\n dp[0][0] = 0;\n for(int i=1;i<=m;i++) {\n dp[i][0] = i...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(const std::string& word1, const std::string& word2) {\n std::vector<std::vector<std::optional<int>>> memo(\n word1.size() + 1,\n std::vector<std::optional<int>>(word2.size() + 1)\n );\n std::function<int(int, int)> ba...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n //all possible ways, kind of inclusion exclusion\n int usingRecursion(string &word1,string &word2, int i, int j){\n if(i>=word1.size()){\n return word2.size() - j;\n }\n if(j>=word2.size()){\n return word1.size() - i;\n }\n...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n const int N = word1.size();\n const int M = word2.size();\n std::vector<std::vector<int>> cache(N, std::vector<int>(M, 0));\n std::vector<std::vector<int>> in_cache(N, std::vector<int>(M, 0));\n\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n string temp;\n if (word1.size() < word2.size()) {\n temp = word1;\n word1 = word2;\n word2 = temp;\n }\n if (word1.size() == 0)\n return word2.size();\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n static int minDistance(const string& word1, const string& word2) {\n short dp[5001][5001];\n // int m{}, n{};\n int m = (int)word1.size();// rows word2Target\n int n = (int)word2.size();//cols word1 WordToBeEdited\n for (int i = 0; i <= max(...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\n void display(vector<vector<int>> dp){\n for(int i=0;i<dp.size();++i){\n for(int j=0;j<dp[0].size();++j){\n cout<<dp[i][j]<<\" \";\n }\n cout<<endl;\n }\n cout<<endl;\n }\n int solve(string &w1,string &w2){\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\nlong long dp[1005][1005];\n Solution() {\n memset(dp, -1, sizeof(dp));\n }\n int minDistance(string word1, string word2) {\n int m = word1.length();\n int n = word2.length();\n return solve(word1,word2, m, n);\n }\n int solve(string& a, ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int n = word1.size();\n int m = word2.size();\n if (n == 0) return m;\n if (m == 0) return n;\n vector<vector<int>> dp;\n for (int i = 0; i <= n; ++i) {\n vector<int> vec;\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "struct pair_hash {\n template <class T1, class T2>\n std::size_t operator() (const std::pair<T1, T2>& p) const {\n auto hash1 = std::hash<T1>{}(p.first);\n auto hash2 = std::hash<T2>{}(p.second);\n return hash1 ^ hash2; // Combine the two hashes\n }\n};\n\nclass Solution {\npu...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "struct pair_hash {\n template <class T1, class T2>\n std::size_t operator() (const std::pair<T1, T2>& p) const {\n auto hash1 = std::hash<T1>{}(p.first);\n auto hash2 = std::hash<T2>{}(p.second);\n return hash1 ^ hash2; // Combine the two hashes\n }\n};\n\nclass Solution {\npu...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n\n /*\n 01234\n horse\n 0 r 12234 j-1+(same or not)\n 1 o i1234 min((j-1,i-1),i-1)+same or not\n 2 s ii223 \n */\n\n const int IMAX = int(1e5);\n string w1, w2;\n map<pair<int,int>,int> memo;\n int dp(int i1, int i2) {\n if(i1 >= w1...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n\n /*\n 01234\n horse\n 0 r 12234 j-1+(same or not)\n 1 o i1234 min((j-1,i-1),i-1)+same or not\n 2 s ii223 \n */\n\n // PUJI TUHAN YESUS\n\n const int IMAX = int(1e5);\n string w1, w2;\n map<pair<int,int>,int> memo;\n int dp(int i1, int...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int n = word1.length(), m = word2.length();\n map<pair<int, int>, int> mp;\n function<int (int, int)> f = [&](int i, int j) {\n if (i == n) return m - j;\n if (j == m) return n - i;\n\n...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n map<pair<int,int>,int>dp;\n int compute(int i,int j,string &word1, string& word2){\n if(i==word1.size()&&j==word2.size())return 0; //if end together, word has been edited properly\n if(i>word1.size()||j>word2.size())return 1e6; //if dissimar, wrong answer\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int m = word1.size();\n int n = word2.size();\n\n // vector<vector<int>> dp(m + 1, vector<int>(n + 1, -1));\n\n // for (int i = 0; i < m; i++) {\n // for (int j = 0; j < n; j++) {\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "#include <bits/stdc++.h>\n#define ss second\n#define ff first\n#define pii pair<int,int>\n#define pb push_back\n#define ll long long\n#define vi vector<int>\n#define vvi vector<vi>\n#define vll vector<ll>\t\n#define pll pair<ll,ll>\n#define vpll vector<pll>\n#define vvll vector<vll>\n#define ld long double...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(std::string word1, std::string word2) {\n memo.clear(); // Clear memoization table before each call\n return editDistance(word1, word2, word1.length(), word2.length());\n }\n\nprivate:\n std::unordered_map<std::string, int> memo; // Memoi...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n unordered_map<string,int>mp;\n int lev(string &w1, string &w2, int m, int n){\n if(m == 0 && n == 0)\n return 0;\n\n if(m == 0)\n return n;\n if(n == 0)\n return m;\n string key = to_string(m) + \" \" + to_string(n);\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n unordered_map<string,int> um;\n int f(string& w1, string& w2, int i, int j, vector<vector<int>> &dp)\n {\n if(i==w1.size()) return w2.size()-j;\n if(j==w2.size()) return w1.size()-i;\n string key = to_string(i)+\",\"+to_string(j);\n if(um.fin...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\n\n int minDistanceHelper(const string& word1, const string& word2, int idx1, int idx2, unordered_map<string, int>& memo) {\n string key = to_string(idx1) + \",\" + to_string(idx2);\n if (memo.find(key) != memo.end()) {\n return memo.at(key);\n }\n\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int f(int ind1, int ind2, string s1, string s2, vector<vector<int>>& dp) {\n if (ind1 == 0)\n return ind2;\n if (ind2 == 0)\n return ind1;\n if (dp[ind1][ind2] != -1)\n return dp[ind1][ind2];\n if (s1[ind1 - 1] == s...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int f(int ind1, int ind2, string s1, string s2, vector<vector<int>>& dp) {\n if (ind1 == 0)\n return ind2;\n if (ind2 == 0)\n return ind1;\n if (dp[ind1][ind2] != -1)\n return dp[ind1][ind2];\n if (s1[ind1 - 1] == s...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "const int NONE = -1;\n\nclass Solution\n{\n\tint solve(\n\t\tconst std::string& from, std::size_t fromIdx,\n\t\tconst std::string& to, std::size_t toIdx,\n std::vector<std::vector<int>>& cache)\n\t{\n int& cachedResult = cache[fromIdx][toIdx];\n if(cachedResult != NONE)\n re...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\nint helper(string&word1, string&word2, int i, int j, int n, int m, unordered_map<int, unordered_map<int, int> >&mp) {\n if(i == n) {\n return m-j;\n }\n if(j == m) {\n return n-i;\n }\n if(mp.find(i) != mp.end() && mp[i].find(j) != mp[i].end()) {\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "const int NONE = -1;\n\nclass Solution\n{\n\tint solve(\n\t\tconst std::string& from, std::size_t fromIdx,\n\t\tconst std::string& to, std::size_t toIdx,\n std::vector<std::vector<int>>& cache)\n\t{\n if(toIdx == to.size() && fromIdx == from.size())\n\t\t\treturn 0;\n\n if(toIdx == to....
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "const int NONE = -1;\n\nclass Solution\n{\n\tint solve(\n\t\tconst std::string& from, std::size_t fromIdx,\n\t\tconst std::string& to, std::size_t toIdx,\n std::vector<std::vector<int>>& cache)\n\t{\n int& cachedResult = cache[fromIdx][toIdx];\n if(cachedResult != NONE)\n re...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\nint helper(string&word1, string&word2, int i, int j, int n, int m, map<int, map<int, int> >&mp) {\n if(i == n) {\n return m-j;\n }\n if(j == m) {\n return n-i;\n }\n if(mp.find(i) != mp.end() && mp[i].find(j) != mp[i].end()) {\n return mp[i][j]...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "const int NONE = -1;\n\nclass Solution\n{\n\tint solve(\n\t\tconst std::string& from, std::size_t fromIdx,\n\t\tconst std::string& to, std::size_t toIdx,\n std::vector<std::vector<int>>& cache)\n\t{\n int& cachedResult = cache[fromIdx][toIdx];\n if(cachedResult != NONE)\n re...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "const int NONE = -1;\n\nclass Solution\n{\n\tint solve(\n\t\tconst std::string& from, std::size_t fromIdx,\n\t\tconst std::string& to, std::size_t toIdx,\n std::vector<std::vector<int>>& cache)\n\t{\n if(toIdx > to.size() || fromIdx > from.size())\n return std::numeric_limits<int>:...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\nint m,n;\n int solve(int i,int j,string ans,string &s1,string &s2,vector<vector<int>>&dp)\n { \n if(i==m && j==n)\n {\n if(s2==ans)\n return 0;\n else\n return 1e8;\n }\n if(i==m)\n {\n return ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int mini = INT_MAX;\n int helper(string &a ,string &b, int i,int j,int cnt,vector<vector<int>>&dp,string s){\n // if(s == b){\n // mini = min(mini,cnt);\n // return 0;\n // }\n // if(i >= a.size() || j >= b.size()) return 0;\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int helper(string &a ,string &b, int i,int j,int cnt,vector<vector<int>>&dp,string s){\n if(i == a.size())return dp[i][j] = b.size() - j;\n if(j == b.size())return dp[i][j] = a.size() - i;\n if(dp[i][j] != -1) return dp[i][j];\n int p=0,q=0,r=0;\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int n=size(word1),m=size(word2);\n unordered_map<int,unordered_map<int,int>> dp;\n for(int i=0;i<n;i++) dp[i][m]=n-i;\n for(int j=0;j<m;j++) dp[n][j]=m-j;\n\n for(int i=n-1;i>=0;i--){\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n unordered_map<int,int> dp;\n int recurse(int i, int j, string &s, string &t) {\n if(j == t.size()) return int(s.size()) - i;\n if(i == s.size()) return int(t.size()) - j;\n if(dp.find(i<<9|j) != dp.end()) return dp[i<<9|j];\n\n int res = INT_MAX...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n if (word1.empty()) {\n return word2.size();\n } \n if (word2.empty()) {\n return word1.size();\n }\n const int INSERT = 0;\n const int DELETE = 1;\n const in...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n map<int,int> dp;\n int recurse(int i, int j, string &s, string &t) {\n if(j == t.size()) return int(s.size()) - i;\n if(i == s.size()) return int(t.size()) - j;\n if(dp.find(i<<9|j) != dp.end()) return dp[i<<9|j];\n\n int res = INT_MAX;\n\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "// // ATTEMPT 1\n// class Solution {\n// map<string,int> dp; \n// public:\n// int minDistance(string x, string y) {\n// if(dp.find(x+\"#\"+y) != dp.end()){\n// return dp[x+\"#\"+y];\n// }\n\n// if(x.length() == 0) return y.length();\n// if(y.length() == 0...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n string s1,s2;\n map<pair<int,int>,int> mp;\n int m(int i, int j){\n return s1[i]!=s2[j];\n }\n int cost(/*int i, int j*/){\n /* if (i==-1 && j==-1)return 0;\n if (i==-1)return j+1;\n if (j==-1)return i+1;\n if (mp.count({i,j}))ret...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\nint minDistance(string word1, string word2) {\n map<pair<int,int>,int> grid;\n for(int i = 0 ; i <= word1.size() ; i++){\n grid[{0,i}] = i;\n }\n for(int i = 0 ; i <= word2.size() ; i++){\n grid[{i,0}] = i;\n }\n for(int i = 1 ; i <= word2.size() ;...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n std::unordered_map<int,int> dp;\n std::function<int(int,int)> lcs;\n lcs = [&dp, &lcs,\n word1 = std::as_const(word1),\n word2 = std::as_const(word2)](int i1, int i2)->int{\n if(i1<0...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int dp[501][501];\n int solve1(int i,int j,string s1,string s2)\n {\n if(i >= s1.size()) {\n return (int)s2.size() - j;\n }\n if(j >= s2.size()) {\n return (int)s1.size() - i;\n }\n if(s1[i] == s2[j]) {\n ...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n int len1 = word1.size();\n int len2 = word2.size();\n unordered_map<int,map<int,int>>dp;\n for(int i = 0; i <= len1; i++) dp[i][0] = i;\n for(int j = 0; j <= len2; j++) dp[0][j] = j;\n\n for(i...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class hasher {\npublic:\n long long int operator() (pair<int, int> a) const {\n long long int ans = a.first;\n ans <<= 32;\n ans += a.second;\n return ans;\n }\n};\n\nclass Solution {\nprivate:\n int recurser(string& word1, string& word2, int pos1, int pos2, unordered_m...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistanceHelper(string& word1 , string word2 , int i , int j , int dp[501][501]){\n if(i == word1.size() && j == word2.size()) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n if(i == word1.size()) return word2.size() - j;\n if(j == word2.si...
72
<p>Given two strings <code>word1</code> and <code>word2</code>, return <em>the minimum number of operations required to convert <code>word1</code> to <code>word2</code></em>.</p> <p>You have the following three operations permitted on a word:</p> <ul> <li>Insert a character</li> <li>Delete a character</li> <li>Rep...
3
{ "code": "class Solution {\npublic:\n int minDistanceHelper(string& word1 , string word2 , int i , int j , int dp[501][501]){\n if(i == word1.size() && j == word2.size()) return 0;\n if(i == word1.size()) return word2.size() - j;\n if(j == word2.size()) return word1.size() - i;\n if(d...