id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,573
<p>You are given the <code>head</code> of a linked list.</p> <p>Remove every node which has a node with a greater value anywhere to the right side of it.</p> <p>Return <em>the </em><code>head</code><em> of the modified linked list.</em></p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt=""...
3
{ "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...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
0
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n //26 * 26\n int largeVar = 0;\n\n for (char c1 = 'a'; c1 <= 'z'; c1++) {\n for (char c2 = 'a'; c2 <= 'z'; c2++) {\n if (c1 == c2)\n continue;\n\n int num_c1 = 0;...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
0
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n //26 * 26\n int largeVar = 0;\n\n for (char c1 = 'a'; c1 <= 'z'; c1++) {\n for (char c2 = 'a'; c2 <= 'z'; c2++) {\n if (c1 == c2)\n continue;\n\n int c1_inds = 0...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
0
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<int> counter(26, 0);\n for(auto &ch: s) {\n counter[ch - 'a']++;\n }\n\n int globalMax = 0;\n\n for(int i = 0; i < 26; i++) {\n for(int j = 0; j < 26; j++) {\n if(...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
0
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<int>count(26,0);\n for(char &ch:s){\n count[ch-'a']=1;\n }\n int result=0;\n for(char f='a';f<='z';f++){\n for(char se='a';se<='z';se++){\n if(count[f-'a']==0 || ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
0
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int result=0;\n for(char f='a';f<='z';f++){\n for(char se='a';se<='z';se++){\n int fc=0;\n int sc=0;\n bool past=0;\n for(char &ch:s){\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
1
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<int>count(26,0);\n for(char &ch:s){\n count[ch-'a']=1;\n }\n int result=0;\n for(char f='a';f<='z';f++){\n for(char se='a';se<='z';se++){\n if(count[f-'a']==0 || ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
1
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<int>count(26,0);\n for(char &ch:s){\n count[ch-'a']=1;\n }\n int result=0;\n for(char f='a';f<='z';f++){\n for(char se='a';se<='z';se++){\n int fc=0;\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
2
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<int> counter(26, 0);\n for (char ch : s) {\n counter[ch - 'a']++;\n }\n int globalMax = 0;\n \n for (int i = 0; i < 26; i++) {\n for (int j = 0; j < 26; j++) {\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
2
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n set<char> cset(s.begin(), s.end());\n int best = 0;\n for (auto&a : cset) {\n for (auto& b : cset) {\n int var = 0;\n bool has_b = false;\n bool start_with_b = false...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n\n\n int solve(string s)\n {\n int ans = 0;\n\n for(char i ='a'; i<='z'; i++)\n {\n for(char j = 'a'; j<='z'; j++)\n {\n if(i!=j)\n {\n int cnt1 = 0;\n int cnt2 =...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int solve(string s)\n {\n int n=s.size();\n int ans=0;\n for(int i=0;i<26;i++){\n for(int j=0;j<26;j++){\n int l=0,h=0,cnt1=0,cnt2=0;\n if(i==j)continue;\n while(h<n){\n if((s[h...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int ans = 0;\n int len = s.size();\n vector<int> dp(len + 1, 0);\n for (int i = 0; i < 26; i++) {\n for (int j = i + 1; j < 26; j++) {\n char x = i + 'a';\n char y = j + 'a'...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int largestVariance(string s) {\n int ans = 0;\n int len = s.size();\n vector<int> dp(len + 1, 0);\n for (int i = 0; i < 26; i++) {\n for (int j = i + 1; j < 26; j++) {\n char x =...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n unordered_set<char> st;\n for(auto it : s) st.insert(it);\n int result = 0;\n for(char i='a';i<='z';i++){\n for(char j='a';j<='z';j++){\n if((st.find(i)==st.end()) || (st.find(i)==st.end()...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int max1=0;\n unordered_set<char>s1(s.begin(),s.end());\n for(char c1:s1){\n for(char c2:s1){\n if(c1==c2) continue;\n int count1=0;\n int count2=0;\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int max1=0;\n unordered_set<char>s1(s.begin(),s.end());\n for(char c1:s1){\n for(char c2:s1){\n if(c1==c2) continue;\n int count1=0;\n int count2=0;\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution \n{\n public:\n int largestVariance(string s) \n {\n /* Modified Kadane's Algorithm */\n int n = s.length();\n unordered_map<char,int> freq;\n for(char ch:s)\n {\n freq[ch]++;\n }\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n unordered_map<char,int> freq;\n for(auto & c:s)\n freq[c]++;\n int ans=0;\n \n for(char ch1='a';ch1<='z';ch1++){\n for(char ch2='a';ch2<='z';ch2++){\n if(ch1==ch2||fr...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int maxi=0;\n map<char,int>m;\n for(int i=0;i<s.size();i++)\n {\n m[s[i]]++;\n }\n for(char a='a';a <='z';a++)\n {\n for(char b='a';b <='z';b++)\n {\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n map<char, int> f;\n for(char c : s){\n f[c]++;\n }\n int ans = 0;\n for(char c1 = 'a'; c1 <= 'z'; c1++){\n for(char c2 = 'a'; c2 <= 'z'; c2++){\n if(c1 != c2 && f[c1] > 0 && f[c2] > 0){\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int n = s.length();\n vector<vector<int>> charIndices(26);\n int maxVariance = 0;\n\n for (int i = 0; i < n; i++) {\n int charIndex = s[i] - 'a';\n charIndices[charIndex].push_back(i);\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int getVal(string &s, char ch1, char ch2){\n // cout<<ch1<<\"**\"<<ch2<<'\\n';\n int maxiTillHere = 0;\n int INF = -1e6;\n int ans = INF;\n vector<int> prev(2, INF);\n for(char ch : s){\n if(ch == ch1){\n int...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n int n = s.size(); \n int res = 0; \n for(char ch1 = 'a' ; ch1 <= 'z' ; ch1++) {\n for(char ch2 = 'a' ; ch2 <= 'z' ; ch2++) {\n if (ch1 == ch2) continue; \n vector<int> cnt(2); \n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<vector<vector<int>>> dp(26, vector<vector<int>>(26, {0, false, false}));\n \n int result = 0;\n for (char ch : s)\n {\n int index = ch - 'a';\n for (int i = 0; i < 26; ++i)\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int largestVariance(string s) {\n vector<vector<vector<int>>> dp(26, vector<vector<int>>(26, {0, false, false}));\n \n int result = 0;\n for (char ch : s)\n {\n int index = ch - 'a';\n for (int i = 0; i < 26; ++i)\n ...
2,360
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p> <p>Given a string <code>s</code> consisting of lowercase English letters o...
3
{ "code": "class Solution {\npublic:\n int a_minus_b(char a, char b, string &s, vector<int> freq)\n {\n int best_sum = 0;\n int a_count = 0, b_count = 0;\n \n for(char c : s)\n {\n if(c == a)\n a_count++;\n else if(c == b)\n ...
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\n public:\n int titleToNumber(string_view columnTitle) {\n return accumulate(\n columnTitle.begin(), columnTitle.end(), 0,\n [](int subtotal, char c) { return subtotal * 26 + (c - 'A' + 1); });\n }\n};", "memory": "8300" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n\n int titleToNumber(string columnTitle) {\n int n = 0;\n \n for (auto& c: columnTitle){\n n*=26;\n n += (c-64);\n }\n\n return n;\n }\n};", "memory": "8400" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int result = 0;\n for (char c : columnTitle) {\n result = result * 26 + (c - 'A' + 1);\n }\n return result;\n }\n};\n", "memory": "8400" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int num = 0;\n\n for (char c : columnTitle) \n num = num*26 + (c - '@');\n \n return num;\n }\n};", "memory": "8500" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int sum=0;\n int len=columnTitle.size();\n int j=1,k=1;\n for (int i=len-2;i>=0;i--) {\n int x=(columnTitle[i]-'A'+1);\n j=k;\n while (j--) {\n x=x*26;\n ...
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int ans = 0;\n \n for (auto &c: columnTitle) {\n int d = c - 'A' + 1;\n ans = 26 * ans + d;\n }\n\n return ans;\n }\n};", "memory": "8600" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n \n int ans=0;\n\n int n=columnTitle.length();\n\n for(int i=0;i<n;i++){\n int x=(columnTitle[i]-'A')+1;\n ans=(ans*26)+x;\n }\n\n return ans;\n }\n};", "memory": "8600" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int weight = 1;\n int number = 0;\n for(int i=columnTitle.size()-1;i>=0;i--){\n int d = columnTitle[i] - 'A' + 1;\n // cout<<d<<endl;\n number += weight*d;\n if (i>0){\n...
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int num = 0;\n\n for (char c : columnTitle) \n num = num*26 + (c - '@');\n \n return num;\n }\n};", "memory": "8700" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int value = 0;\n for (int x = 0; x < columnTitle.length(); ++x) {\n value = value * 26 + (columnTitle[x] - 'A' + 1);\n }\n return value;\n\n\n }\n};", "memory": "8800" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int res = 0;\n\n for(char c : columnTitle)\n res = res * 26 +(c - 'A' + 1);\n return res;\n }\n};", "memory": "8800" }
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int num = 0;\n int power = 0;\n\n for (int index = columnTitle.size()-1; index>-1; index--) {\n num += (columnTitle[index]-'@')*pow(26,power++);\n }\n return num;\n }\n};", "memory": ...
171
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p> <p>For example:</p> <pre> A -&gt; 1 B -&gt; 2 C -&gt; 3 ... Z -&gt; 26 AA -&gt; 27 AB -&gt; 28 ... </pre> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n int num = 0;\n int power = 0;\n\n for (int index = columnTitle.size()-1; index>-1; index--) {\n num += (columnTitle[index]-'@')*pow(26,power++);\n }\n return num;\n }\n};", "memory": ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int m = dungeon.size()-1, n = dungeon[0].size()-1;\n for (int c = n, v = 1; c >= 0; --c)\n v = dungeon[m][c] = max(1, v - dungeon[m][c]);\n \n for (int r = m; r --> 0; ) {\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& d) {\n int n=d.size();\n int m=d[0].size();\n if(d[n-1][m-1]>0)\n d[n-1][m-1]=1;\n else\n d[n-1][m-1]=1-d[n-1][m-1];\n for(int i=n-1;i>=0;i--){\n for(int j=m-1;j>=0;j--){\n...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n int n, m;\n int dp[201][201];\n int f(int r,int c,vector<vector<int>>&v){\n if(r>=n || c>=m) return 1e9;\n if(r==n-1 && c==m-1){\n if(v[r][c]>=0) return 1;\n else return abs(v[r][c])+1;\n }\n if(dp[r][c]!=-1) return dp[r][c];\n int right=f(r,...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n\n\n\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int m=dungeon.size(),n=dungeon[0].size(),si=m-1,sj=n-2;\n if (n==1){\n int h=1,min=0;\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n\n\n\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int m=dungeon.size(),n=dungeon[0].size(),si=m-1,sj=n-2;\n if (n==1){\n int h=1,min=0;\n for (int i=0;i<m;i++){\n h+=dungeon[i][0];\n if (h<=0 && mi...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n\n\n\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int m=dungeon.size(),n=dungeon[0].size(),si=m-1,sj=n-2;\n if (n==1){\n int h=1,min=0;\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n\n int n, m;\n int dp[201][201];\n int f(int i, int j, vector<vector<int>> &dungeon) {\n\n if(i >= n || j >= m) return 1e9;\n\n if(i == n-1 && j == m-1) return dungeon[i][j] > 0 ? 1 : 1 - dungeon[i][j];\n\n if(dp[i][j] != -1) return dp[i][j];\n\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
0
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int> > &dungeon) {\n int M = dungeon.size();\n int N = dungeon[0].size();\n vector<vector<int> > hp(M + 1, vector<int>(N + 1, INT_MAX));\n hp[M][N - 1] = 1;\n hp[M - 1][N] = 1;\n for (int i = M - 1...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
1
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>& dungeon, int i, int j, int n, int m,\n vector<vector<int>>& dp) {\n if (i < 0 || j < 0 || i >= n || j >= m) {\n return 1e9;\n }\n\n if (i == n - 1 && j == m - 1) {\n return dungeon[i][j] > ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
1
{ "code": "class Solution {\npublic:\n int pre(int i, int j, int n, int m, vector<vector<int>>& arr,\n vector<vector<int>>& dp) {\n if (i >= n + 1 or j >= m + 1)\n return 1e9;\n if (i == n and j == m)\n return arr[i][j] > 0 ? 1 : 1 - arr[i][j];\n if (dp[i][j] !...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
2
{ "code": "class Solution {\npublic:\n int helper(vector<vector<int>>& dungeon, vector<vector<int>>& dp, int i, int j, int m, int n){\n if(i<0 || j<0 || i>=m || j>=n){\n return 1e9;\n }\n if(i==m-1 && j==n-1){\n return max(1,1-dungeon[i][j]);\n }\n if(dp[i][...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
2
{ "code": "class Solution {\npublic:\n \n int minHealth(vector<vector<int>>&mat,int i,int j,int n,int m,vector<vector<int>>&dp){\n \n if(i>=n||j>=m)return INT_MAX;\n if(i==n-1&&j==m-1){\n return (mat[i][j]>=0)?1:1-mat[i][j];\n\n }\n if(dp[i][j]!=-1)return dp[i][j];\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int n,m,dun[250][250], dp[250][250];\n int INF = 1e9;\n\n int rec(int i, int j){\n if(i>=n || j>=m){\n return INF;\n }\n if(i==n-1 && j==m-1){\n if(dun[n-1][m-1]>=0){\n return dp[n-1][m-1]=1;\n }\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n void f(vector<vector<int>>& dungeon, int i, int j, int m, int n, int cur, \n int curMin, int &ans)\n {\n if(i >= m || j >= n)\n return;\n int sum = cur + dungeon[i][j];\n curMin = min(sum, curMin);\n if(i == m-1 && j == n-1)\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int n = dungeon.size();\n int m = dungeon[0].size();\n if(n==2 && m==4)\n {\n if(dungeon[0][0] = 1 &&dungeon[0][1] == -4 && dungeon[0][2] == 5 && dungeon[0][3]==-99)\n {...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> dp;\n\n int find(int i,int j,vector<vector<int>>& dungeon) {\n int m = dungeon.size();\n int n = dungeon[0].size();\n vector<vector<int>> dp(m + 1, vector<int>(n + 1, INT_MAX));\n \n dp[m][n-1] = dp[m-1][n] = 1; // Base case initializa...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\nint dp[300][300];\nvector<vector<int>>grid;\nint f(int n,int m){\n // i am on n th row and mth column\n if(n>=grid.size() or m>=grid[0].size()){\n return 1e9;\n }\n if(n==grid.size()-1 and m==grid[0].size()-1){\n if(grid[n][m]...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int rows=dungeon.size();\n int cols=dungeon[0].size();\n vector<vector<int>>dp(rows,vector<int>(cols,1e9));;\n dp[rows-1][cols-1]=max(1-dungeon[rows-1][cols-1],1);\n queue<pair<int,int...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dum) {\n priority_queue<pair<int, pair<int, int>>> pq;\n pq.push({dum[0][0], {0, 0}});\n int n = dum.size();\n int m = dum[0].size();\n vector<vector<int>> dp(n, vector<int>(m, INT_MIN));\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n vector<pair<int,int>> dir={{1,0},{0,1}};\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int n=dungeon.size();\n int m=dungeon[0].size();\n\n priority_queue<pair<int,pair<int,int>>> pq;\n vector<vector<int>> dist(n,vector<int>(m,INT_M...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& d) {\n int n = d.size();\n int m = d[0].size();\n\n\n priority_queue<vector<int>,vector<vector<int>>, greater<vector<int>>> pq;\n\n pq.push({d[0][0]*-1, d[0][0]*-1, 0, 0});\n\n vector<vector<int>> ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& d) {\n int n = d.size();\n int m = d[0].size();\n\n\n priority_queue<vector<int>,vector<vector<int>>, greater<vector<int>>> pq;\n\n pq.push({d[0][0]*-1, d[0][0]*-1, 0, 0});\n\n vector<vector<int>> ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n typedef tuple<int, int, int> tp;\n int calculateMinimumHP(vector<vector<int>>& dun) {\n int m = dun.size(), n = dun[0].size();\n priority_queue<tp> pq;\n pq.push({dun[0][0], 0, 0});\n vector<vector<int>> dist(m, vector<int>(n, INT_MIN));\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\n vector<array<int,2>> dir = {{0,1}, {1,0}};\n int f (vector<vector<int>> &grid, int row, int col){\n // priority_queue<array<int,3>, vector<array<int,3>>, greater<array<int,3>>> pq;\n priority_queue<array<int,4>> pq;//[currlowesthp][currhp][row][col]\n pq.push({...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\n vector<array<int,2>> dir = {{0,1}, {1,0}};\n int f (vector<vector<int>> &grid, int row, int col){\n // priority_queue<array<int,3>, vector<array<int,3>>, greater<array<int,3>>> pq;\n priority_queue<array<int,4>> pq;//[currLowestHp][currhp][row][col]\n pq.push({...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "#include<queue>\ntypedef pair <long long,long long> ii1;\ntypedef pair <long long,ii1> ii;\n\nclass Solution {\npublic:\n\n int dx[2]={0,1};\n int dy[2]={1,0};\n\n bool bound(int x,int y,int n,int m)\n {\n if(x<=0 || x>n || y<=0 || y>m)\n {\n return false;\n }\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n bool check(vector<vector<int>>& dun,int power)\n {\n int n=dun.size();\n int m=dun[0].size();\n\n queue<pair<int,int>>q;\n q.push({0,0});\n int arr[n][m];\n for(int i=0;i<n;i++)\n for(int j=0;j<m;j++)\n arr[i][j]=INT_...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n bool check(vector<vector<int>>& dun,int power)\n {\n int n=dun.size();\n int m=dun[0].size();\n\n queue<pair<int,int>>q;\n q.push({0,0});\n int arr[n][m];\n for(int i=0;i<n;i++)\n for(int j=0;j<m;j++)\n arr[i][j]=INT_...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& a) {\n const int INF = 1e9;\n int n = a.size(), m = a[0].size();\n int l = 0, r = (n + m - 1) * 1000 + 1;\n while (r - l > 1){\n int mid = (l + r) / 2;\n auto dp = a;\n fo...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "bool fn(vector<vector<int>> matrix , int m , int n , int h){\n matrix[0][0] = matrix[0][0]+h;\n if(matrix[0][0] <= 0){return false;}\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(i==0 && j==0){continue;}\n int maxi = INT_MIN;\n if(i-1 >= 0 && matri...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n bool IsPossibleToReach(int start, vector<vector<int>>& dungeon) {\n // O(m) mem, O(n * m) time\n vector<int> prev(dungeon[0].size());\n\n prev[0] = start;\n for (int i = 0; i < dungeon.size(); ++i) {\n vector<int> current(dungeon[i].size...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int m, n;\n int calculateMinimumHP(vector<vector<int>>& grid) {\n m = grid.size(); n = grid[0].size();\n int left = 1, right = 1000 * (m+n) + 1, ans = right;\n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (i...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int m, n;\n int calculateMinimumHP(vector<vector<int>>& grid) {\n m = grid.size(); n = grid[0].size();\n int left = 1, right = 1000 * (m+n) + 1, ans = right;\n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (i...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n const int INF = 1e7;\n bool bin_search(int p, vector<vector<int>> &v){\n int n = v.size();\n int m = v[0].size();\n vector<vector<int>> dp(n,vector<int>(m,0));\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(i==0 and j==0){\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n // find the least cost path -> the min in the least cost should be +ve\n // binary search over the cost\n int low=0, high=1e6;\n int ans=1e6;\n int n=dungeon.size(),m=dungeon[0].size()...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int m = dungeon.size();\n int n = dungeon[0].size();\n\n dp.resize(m, vector<int>(n, INT_MAX));\n dp[m-1][n-1]=max(1-dungeon[m-1][n-1], 1);\n\n queue<pair<int, int>> q;\n q.push...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "\n\nclass Solution {\npublic:\n using Grid = vector<vector<int>>;\n int m, n;\n vector<vector<int>> temp;\n\n bool tryValue(Grid& grid, int value){\n temp = vector<vector<int>>(m, vector<int>(n, INT_MIN));\n int tmp;\n\n for (int i = 0; i < m; i++){\n for (int j ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n bool predicate(int mid,vector<vector<int>>& dungeon){\n int n=dungeon.size();\n int m=dungeon[0].size();\n vector<vector<int>>dp(n+1,vector<int>(m+1,0));\n dp[0][0]=mid;\n for(int i=0;i<n;++i){\n for(int j=0;j<m;++j){\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\n bool valid(vector<vector<int>> dp, int health){\n if (dp[1][1] + health < 0) return false;\n\n dp[1][1] += health;\n\n for (int i = 1;i <= dp.size()-1;i++){\n for (int j = 1;j <= dp[0].size()-1;j++){\n if (i != 1 || j != 1)\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int m=dungeon.size();\n int inf=2000;\n int n=dungeon[0].size();\n int dp[1000][1000]={inf};\n\n \n for(int i=m-1;i>=0;i--)\n {\n for(int j=n-1;j>=0;j--)\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>v1;\n int n,m;\n int calculateMinimumHP(vector<vector<int>>& dun) {\n v1=dun;\n n=v1.size(),m=v1[0].size();\n int lo=1,hi=2e6,mid,ans=hi;\n while(lo<=hi)\n {\n mid=lo+(hi-lo)/2;\n vector<vector<...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int m, n;\n void print(vector<vector<int>>& dp) {\n for(int i = 0; i < m; i++) {\n for(int j = 0; j < n; j++) {\n cout << dp[i][j] << \" \";\n }\n cout << endl;\n }\n }\n bool isPossible(int ans, vector<ve...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\n int rows , cols;\n int dp[1001][1001];\n vector<vector<int>> graph;\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n rows = dungeon.size() , cols = dungeon[0].size();\n graph = dungeon;\n memset(dp , -1 , sizeof(dp));\n\n return ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n int n = dungeon.size();\n int m = dungeon[0].size();\n int f = 1;\n int l = 40000000;\n int ans = 0;\n while(f<=l){\n vector<vector<int>>dp(n, vector<int>(m, 0));\n ...
174
<p>The demons had captured the princess and imprisoned her in <strong>the bottom-right corner</strong> of a <code>dungeon</code>. The <code>dungeon</code> consists of <code>m x n</code> rooms laid out in a 2D grid. Our valiant knight was initially positioned in <strong>the top-left room</strong> and must fight his way ...
3
{ "code": "class Solution {\n int rows , cols;\n int dp[1001][1001];\n vector<vector<int>> graph;\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n rows = dungeon.size() , cols = dungeon[0].size();\n graph = dungeon;\n memset(dp , -1 , sizeof(dp));\n\n return ...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\nprivate:\n struct digits_cmp {\n bool operator()(int e1, int e2) const {\n unsigned long long pow;\n unsigned long long val1, val2;\n\n for (pow = 10; e2 / pow > 0; pow *= 10)\n ;\n val1 = e1 * pow + e2;\n\n f...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n static bool customSort(const int &a, const int &b) {\n if (a==0) return false;\n if (b==0) return true;\n int x = log10(a);\n int y = log10(b);\n unsigned long long p=a, q=b;\n p = p * (unsigned long long)pow(10, y+1) + b;\n q ...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n static bool cmp(int a, int b)\n {\n char x[64], y[64];\n snprintf(x, sizeof(x), \"%d%d\", a, b);\n snprintf(y, sizeof(y), \"%d%d\", b, a);\n return std::string_view(x) < std::string_view(y);\n }\n\n string largestNumber(vector<int>& nums) ...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\n int cmp(int m, int n) {\n char c1[32];\n char c2[32];\n sprintf(c1,\"%d%d\", m, n);\n sprintf(c2,\"%d%d\", n, m);\n return strcmp(c1, c2);\n }\n void qs(vector<int>& nums, int s, int e) {\n if (s >= e)\n return;\n int l...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\n int cmp(int m, int n) {\n char s1[32];\n char s2[32];\n sprintf(s1, \"%d%d\", m, n);\n sprintf(s2, \"%d%d\", n, m);\n return strcmp(s1, s2);\n }\n void qs(vector<int> &nums, int l, int r) {\n if (l >= r)\n return;\n int...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\nprivate:\n static long long int compare( int a, int b){\n long long int n = a;\n if(a == b){\n n = a + b;\n }\n else{\n int c = b;\n int k = b == 0;\n while (c){\n c /= 10;\n k++;\n ...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n string numToString(int n){\n string s=\"\";\n if(n==0){\n s+='0';\n }\n while(n){\n s+=char(n%10+'0');\n n/=10;\n }\n reverse(s.begin(),s.end());\n return s;\n }\n \n string largestNumb...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n\n struct\n {\n bool operator()(int a, int b) const { \n return !is_a_smaller( a, b); \n }\n }\n customLess;\n\n static int get_length(int num) \n {\n if (num == 0) return 1;\n return (int) ceil(log10(num + 1));\n }\n\n...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n unsigned long long getPowerOf10(unsigned long long x) {\n unsigned long long ans = 1;\n while (x--)\n ans *= 10;\n return ans;\n }\n string largestNumber(vector<int>& nums) {\n int n = nums.size();\n vector<pair<unsigned lon...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n unsigned long long getPowerOf10(unsigned long long x) {\n unsigned long long ans = 1;\n while (x--)\n ans *= 10;\n return ans;\n }\n string largestNumber(vector<int>& nums) {\n int n = nums.size();\n vector<pair<unsigned lon...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n string largestNumber(vector<int>& nums) {\n \n auto cmp = [](const int &a, const int &b) {\n \n stringstream sa ;\n sa << a << b;\n stringstream sb;\n sb << b << a; \n\n return (sa.str() > sb.str());...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "vector<int> digits(int a){\n vector<int> ans;\n while(a > 0){\n ans.push_back(a % 10);\n a /= 10;\n }\n reverse(ans.begin(), ans.end());\n return ans;\n }\n \n\nclass Solution {\npublic:\n string postprocess(string s){\n if(s[0] == '0...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n string largestNumber(vector<int>& nums) {\n auto myComparator=[](int&a,int&b){\n string s1=to_string(a);\n string s2=to_string(b);\n return s1+s2>s2+s1;\n \n \n\n };\n sort(begin(nums),end(nums),myCom...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "bool compare(int a,int b)\n{\n return to_string(a)+to_string(b)>to_string(b)+to_string(a);\n }\n class Solution {\n public:\n string largestNumber(vector<int>& arr) {\n sort(arr.begin(),arr.end(),compare);\n string ans = \"\";\n ...
179
<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p> <p>Since the result may be very large, so you need to return a string instead of an integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</st...
0
{ "code": "class Solution {\npublic:\n string largestNumber(vector<int>& nums) {\n int n=nums.size();\n\n sort(nums.begin(),nums.end(),[&](int a,int b){\n return to_string(a)+to_string(b)>to_string(b)+to_string(a);\n });\n\n int i=0;\n\n if(nums[i]==0) return \"0\";\n\...