id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
2
{ "code": "class Solution {\npublic:\n int findSpecialInteger(const std::vector<int>& arr) {\n const size_t len_arr = arr.size();\n const double len_slice = 1.0 / static_cast<double>(len_arr);\n std::unordered_map<int, double> freq;\n\n for(const int& num : arr) {\n freq[num] += len_slic...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
2
{ "code": "class Solution {\npublic:\n int findSpecialInteger(const std::vector<int>& arr) {\n const size_t len_arr = arr.size();\n const double len_slice = 1.0 / static_cast<double>(len_arr);\n std::unordered_map<int, double> freq;\n for(const int& num : arr) {\n freq[num] += len_slice;\n if(f...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
2
{ "code": "class Solution {\npublic:\n int findSpecialInteger(const std::vector<int>& arr) {\n const double len_slice = 1.0 / static_cast<double>(arr.size());\n std::unordered_map<int, double> freq;\n\n for(const int& num : arr) {\n freq[num] += len_slice;\n if(freq[num] > 0.25) {\n return ...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
2
{ "code": "class Solution {\npublic:\n int findSpecialInteger(vector<int>& arr) {\n unordered_map<int, int> countMap;\n int n = arr.size();\n int threshold = n / 4;\n \n for (int num : arr) {\n countMap[num]++;\n }\n \n for (const auto& pair : coun...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
2
{ "code": "class Solution {\npublic:\n int findSpecialInteger(vector<int>& arr)\n {\n unordered_map<int,int>mp;\n for(int i=0;i<arr.size();i++)\n {\n mp[arr[i]]++;\n }\n for(auto i:mp)\n {\n if(i.second>arr.size()/4)\n {\n ...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
2
{ "code": "class Solution {\npublic:\n int findSpecialInteger(vector<int>& arr) {\n unordered_map <int, int> mp;\n for(auto it : arr) mp[it]++;\n for(auto it : mp){\n if(it.second >= (double)(arr.size() * 0.25)) return it.first;\n }\n return -1;\n }\n};", "memory"...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
3
{ "code": "class Solution {\npublic:\n int findSpecialInteger(vector<int>& arr) {\n // [1,2,2,6,6,6,6,7,10]\n unordered_map<int,int>mp;\n int n=arr.size();\n for(int i=0;i<n;i++){\n mp[arr[i]]++;\n }\n int ans;\n for(auto i : mp)\n {\n i...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
3
{ "code": "class Solution {\npublic:\n int findSpecialInteger(vector<int>& arr) {\n ios_base::sync_with_stdio(false);\n cout.tie(nullptr);\n cin.tie(nullptr);\n\n unordered_map<int, int> my_map {};\n\n for (int x : arr) {\n my_map[x]++;\n }\n\n int max_fr...
1,221
<p>Given an integer array <strong>sorted</strong> in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> arr = [1,2,2,6,6,6,6,7,10] <strong>Output:...
3
{ "code": "class Solution {\npublic:\n int findSpecialInteger(vector<int>& arr) {\n map<int,int> cnt;\n for(auto x:arr)\n ++cnt[x];\n int ans = -1;\n for(auto x:cnt) {\n if(ans == -1)\n ans = x.first;\n else{\n if(x.second >...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\n\n static bool comparator(vector<int> &a,vector<int> &b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n return a[0]<b[0];\n }\n\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(), c...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\nstatic bool comp(vector<int>&a,vector<int>&b){\n if(a[0]==b[0])\n return a[1]>b[1];\n return a[0]<b[0];\n}\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),comp);\n int n=intervals.size();\n i...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end(), [](vector<int>& a, vector<int>& b ) {\n if(a[0] == b[0]) {\n return a[1] >= b[1];\n }\n return a[0] < b[0];\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n int gr = INT_MIN, lo = INT_MIN;\n int res = 0;\n for(auto& i : intervals) {\n if(i[1] <= gr) {\n continue;\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n vector<bool> visit(intervals.size(),false);\n\n for(int i = 0;i<intervals.size();i++){\n for(int j = 0;j<intervals.size();j++){\n if(j == i){\n continue;\...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n // Sort intervals: primary sort by start ascending, secondary sort by end descending\n sort(intervals.begin(), intervals.end(), [](const vector<int>& a, const vector<int>& b) {\n return a[...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "/*\n\nhttps://leetcode.com/problems/remove-covered-intervals/discuss/451277/JavaC++Python-Sort-Solution\n\nhttps://leetcode.com/problems/remove-covered-intervals/discuss/451284/JavaPython-3-Simple-codes-w-explanation-and-analysis.\n\nhttps://leetcode.com/problems/remove-covered-intervals/discuss/451250/Jav...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
0
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n auto comp = [&](const vector<int>& i, const vector<int>& j) {\n if (i[0] == j[0])\n return i[1] > j[1];\n return i[0] < j[0];\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
2
{ "code": "/*\n\nhttps://leetcode.com/problems/remove-covered-intervals/discuss/451277/JavaC++Python-Sort-Solution\n\nhttps://leetcode.com/problems/remove-covered-intervals/discuss/451284/JavaPython-3-Simple-codes-w-explanation-and-analysis.\n\nhttps://leetcode.com/problems/remove-covered-intervals/discuss/451250/Jav...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n struct comp{\n bool operator()(pair<int,int> p1,pair<int,int> p2){\n if(p1.first==p2.first)\n return p1.second<p2.second;\n return p1.first>p2.first;\n }\n };\n \n int removeCoveredIntervals(vector<vector<int>>& inte...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\nbool static cmp(pair<int,int> a,pair<int,int> b)\n{\n if(a.first==b.first)\n return a.second>b.second;\n return a.first<b.first;\n}\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n vector<pair<int,int>> vec;\n for(int i=0;i<intervals.size...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n static bool comp(pair<int,int>a, pair<int,int>b){\n if(a.first == b.first) return a.second > b.second;\n return a.first < b.first;\n } \n int removeCoveredIntervals(vector<vector<int>>& arr) {\n int n = arr.size();\n vector<pair<int,int>>vec;...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n int res=0;\n int start=-1,end=-1;\n sort(intervals.begin(),intervals.end());\n for(vector<int> v:intervals){\n if(v[0]>start && v[1]>end){\n res++;\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n int res = 0,left = -1, right = -1;\n \n sort(intervals.begin(),intervals.end());\n \n for(auto v: intervals){\n if(v[0] > left && v[1] > right){\n left =...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n vector<vector<int>>ans;\n ans.push_back(intervals[0]);\n for(int i=1;i<intervals.size();i++) {\n vector<int>t=ans.back();\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n vector<pair<int, int>> intervalPairs;\n\n for(auto interval: intervals) {\n intervalPairs.push_back({interval[0], interval[1]});\n }\n\n auto comp = [](const pair<int, int>& ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n std::map<int,int>m;\n for(const auto& v:intervals){\n const int l=v[0];\n const int r=v[1];\n if(m.find(l)==m.end()){\n m[l]=r;\n } else {\n...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n //sort(intervals.begin(),intervals.end());\n int n=intervals.size();\n unordered_map<int,bool> mp;\n int cnt=0;\n for(int i=0;i<n;i++)\n {\n if(mp[i]==true)\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),[](const auto&v1,const auto&v2){\n if(v1[0]==v2[0]) return v1[1]>v2[1];\n return v1[0]<v2[0];\n });\n map<int,int>mp;\n int ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),[&](vector<int>&a,vector<int>&b){\n if(a[0]==b[0])return a[1]>b[1];\n return a[0]<b[0];\n });\n\n int ans=intervals.size();\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n stack<vector<int>> st;\n st.push(intervals[0]);\n for(int i=1;i<intervals.size();i++){\n vector<int> temp = st.top();\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),[&](vector<int>&a,vector<int>&b){\n if(a[0]==b[0])return a[1]>b[1];\n return a[0]<b[0];\n });\n\n int ans=intervals.size();\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),[&](vector<int>&a,vector<int>&b){\n if(a[0]==b[0])return a[1]>b[1];\n return a[0]<b[0];\n });\n\n int ans=intervals.size();\n ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "\nstatic bool cmp(const vector<int>&a,const vector<int>&b){\n if(a[0]>b[0]) return false;\n else if(a[0]<b[0]) return true;\n return a[1]>b[1];\n}\nclass Solution {\npublic:\n\n int removeCoveredIntervals(vector<vector<int>> intervals) {\n int maxi=-1;\n sort(intervals.begin(), in...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n #define deb2(x,y) cout<<#x<<\" is \"<<x<<\" and \"<<#y<<\" is \"<<y<<endl;\n #define deb(x) cout<<#x<<\" is \"<<x<<endl;\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n multiset<int> front;\n vector<pair<int,int>> pts;\n int ans = 0;\n...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n set<pair<int, int>> st;\n for(auto it: intervals) st.insert({it[0], it[1]});\n int ans = st.size();\n for(auto it1: st) {\n bool invalid = false;\n for(auto it2: s...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n int n = intervals.size();\n set<vector<int>> removed;\n for(int i = 0; i < n; i++){\n int l = intervals[i][0];\n int r = intervals[i][1];\n if(removed.find(int...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n set<vector<int>> st;\n int k = 0;\n\n for(int i=0;i<intervals.size();i++){\n for(int j=0;j<intervals.size();j++){\n if(i!=j){\n if(intervals[i][0] ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& v) {\n int n=v.size();\n map<int,int>mp;\n vector<vector<int>>rem;\n for(auto &i:v){\n int x=i[0],y=i[1];\n mp[x]=max(mp[x],y);\n }\n for(auto &i:mp)rem.push_back({...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& v) {\n int n=v.size();\n map<int,int>mp;\n vector<vector<int>>rem;\n for(auto &i:v){\n int x=i[0],y=i[1];\n mp[x]=max(mp[x],y);\n }\n for(auto &i:mp)rem.push_back({...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector<vector<int>>& intervals) {\n\n int ctr = 0;\n vector<pair<int, pair<int,int>>> vec;\n for(auto it: intervals)\n {\n vec.push_back({it[1] - it[0], {it[0], it[1]}});\n }\n sort(vec.rbegin(), ...
1,222
<p>Given an array <code>intervals</code> where <code>intervals[i] = [l<sub>i</sub>, r<sub>i</sub>]</code> represent the interval <code>[l<sub>i</sub>, r<sub>i</sub>)</code>, remove all intervals that are covered by another interval in the list.</p> <p>The interval <code>[a, b)</code> is covered by the interval <code>[...
3
{ "code": "class Solution {\npublic:\nbool static comp(vector<int> a1,vector<int> &a2){\n if(a1[0]!=a2[0])\n return a1[0]<a2[0];\n else\n return a1[1]>a2[1];\n}\nint removeCoveredIntervals(vector<vector<int>>& intervals) {\n int n=intervals.size();\n sort(intervals.begin(),intervals.end...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "#define f(i,a,b) for (int i = a; i <b; i++)\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n cout << \"13\\n7\\n7\\n-192\\n-268\\n-44...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "#define f(i,a,b) for (int i = a; i <b; i++)\nstatic const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n cout << \"13\\n7\\n7\\n-192\\n-268\\n-44...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n int minIdx1 = 0;\n int minIdx2 = n-1; \n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n if(grid[i][j] < grid[i][minIdx1]){\n ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n if (n == 1) return grid[0][0];\n \n vector<int> prev(n, 0), curr(n, 0);\n \n for (int j = 0; j < n; ++j) {\n prev[j] = grid[0][j];\n }\n ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "#include <ranges>\nnamespace rn = std::ranges;\nnamespace vw = std::views;\n\nclass Solution {\npublic:\n int minFallingPathSum(std::vector<std::vector<int>>& grid) {\n constexpr int MAX_VAL = 101 * 201;\n const int N = grid.size();\n\n // Keep track of the minimum value for each el...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n for (int row = n - 2; row >= 0; --row) {\n int first_min = INT_MAX, second_min = INT_MAX;\n int first_min_index = -1;\n \n for (int col = 0; c...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
0
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n constexpr int kInf = 1 << 30;\n for (int i = 1; i < grid.size(); i++) {\n for (int j = 0; j < grid.size(); j++) {\n int minimum = kInf;\n for (int k = 0; k < grid.size(...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int n,m;\n int dp[210][210];\n int done[210][210];\n int rec(int i,int j,vector<vector<int>>& grid){\n if(i==n) return 0;\n if(done[i][j]) return dp[i][j];\n int ans=INT_MAX;\n for(int k=0;k<m;k++){\n if(k!=j){\n ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<int> dp = grid[0];\n for (int i = 1; i < n; ++i) {\n vector<int> new_dp(n, INT_MAX);\n for (int j = 0; j < n; ++j) {\n for (int k = 0; ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size(), res = INT_MAX;\n vector<vector<int>> dp(n, vector<int>(n, -1));\n\n for(int j = 0; j < n; ++j) {\n dp[0][j] = grid[0][j];\n }\n\n for(int i = 1; i < n; ++i)...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n if(n == 1) return grid[0][0];\n \n vector<int> prev(n, 0);\n int ans = INT_MIN;\n int l1, l2;\n for(int i = 0; i < n; i++)\n {\n prev...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int solve(vector<vector<int>>&grid,int i,int j,vector<vector<int>>&dp){\n if(i==grid.size())return 0;\n if(dp[i][j+1]!=-1) return dp[i][j+1];\n int ans =1e9;\n for(int k=0;k<grid[0].size();k++){\n if(k!=j){\n ans=min(ans,g...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size(), res = INT_MAX;\n vector<vector<int>> dp(n, vector<int>(n, -1));\n\n for(int j = 0; j < n; ++j) {\n dp[0][j] = grid[0][j];\n }\n\n for(int i = 1; i < n; ++i)...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n if (n == 1) return grid[0][0];\n\n vector<vector<int>> dp(n, vector<int>(n, INT_MAX));\n\n // Initialize the first row of dp with the values from the grid\n for (int...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
1
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n const int n = grid.size();\n if(n == 1) return grid[0][0];\n vector<int> lr(n, 0);\n for(int i{0}; i < n; i++){\n vector<int> current(n, INT_MAX);\n for(int j{0}; j < n; j++...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
2
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size(), res = INT_MAX;\n vector<vector<int>> dp(n, vector<int>(n, -1));\n\n for(int j = 0; j < n; ++j) {\n dp[0][j] = grid[0][j];\n }\n\n for(int i = 1; i < n; ++i)...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
2
{ "code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<vector<int>> dp(n, vector<int>(n, INT_MAX));\n \n // Initialize the first row of dp\n for (in...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n\n class RowMin\n {\n private:\n int m_capacity;\n int m_count;\n int* min;\n int* minIndex;\n \n public:\n RowMin(int capacity) : m_count(0), m_capacity(capacity) {\n min = new int[capacity];\n minIndex = ne...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> dp(n,vector<int> (m,0));\n\n \n int p = 1e9;\n int q = 1e9;\n int pi = 0;\n int qi = 0;\n f...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n\n int n = grid.size();\n\n if(n == 1){\n return grid[0][0];\n }\n if(n == 2){\n return min(grid[0][0] + grid[1][1], grid[1][0] +...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\n void takeLeastTwo(vector<vector<int>> &mn, int val, int idx){ \n if(val < mn[0][0]) mn[1] = mn[0], mn[0] = {val, idx};\n else if(val < mn[1][0]) mn[1] = {val, idx};\n }\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n \nlong long int solve(int i, int j,vector<vector<int>>& grid,vector<vector<long long int>> &dp){\n if(i>=grid.size() ||j>=grid.size()){\n return 0;\n }\n \n long long int ans= INT_MAX;\n if(dp[i][j]!= -1) return dp[i][j];\n for(int k=0; k<grid[0].size(); ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n long long solve(int i,int j,vector<vector<int>>& matrix,int n,vector<vector<long long>>& dp){\n if(j>=n||j<0){\n return 1e9;\n }\n if(i==n-1){\n // cout<<\"n-1\"<<n-1<<endl;\n return matrix[i][j];\n }\n if(dp...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n long long solve(int prev, int idx, vector<vector<int>>& grid, int n, int m, vector<vector<long long>>& dp) {\n if (idx == n) {\n return 0; // Base case: No more rows to process\n }\n\n // Memoization check\n if (prev != -1 && dp[prev][i...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\n vector<vector<int>> dp;\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n\n dp.resize(n, vector<int> (m+1, INT_MAX));\n\n return dfs(grid, 0, m);\n }\n\n int dfs(vector<vector<int>> & g...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\n public:\n int minFallingPathSum(vector<vector<int>>& grid) {\n auto min =\n vector<vector<int>>(grid.size(), vector<int>(grid[0].size(), -1));\n for (int i = 0; i < grid[0].size(); i++) min[0][i] = grid[0][i];\n for (int i = 1; i < grid.size(); i++) {\n for (int j = ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n struct RowDetails\n {\n int mBestCol;\n int mBestNum;\n int mSecondCol;\n int mSecondNum;\n };\n\n int minFallingPathSum(vector<vector<int>>& grid) {\n\n if (grid.size() == 1)\n {\n return grid[0][0];\n }\n\...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n int getMin(int i,int last,int m,int n,vector<vector<int>>&grid,vector<vector<int>>&dp){\n if(i==m)\n return 0;\n int mini=INT_MAX;\n if(dp[i][last]!=-1)\n return dp[i][last];\n for(int k=0;k<m;k++){\n if(k!=last)\n ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n vector<pair<int, int>> ans(grid[0].size());\n\n for (int c = 0; c < grid[0].size(); c++)\n ans[c] = {grid[0][c], c};\n sort(ans.begin(), ans.end());\n // cout << ans[0].first << \", po...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<pair<int, int>> temp;\n for(int i = 0; i < n; ++i){\n temp.push_back({grid[n-1][i], i});\n }\n for(int i = n - 2; i >= 0; --i) {\n vecto...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n unordered_map<int,vector<int>>mp;\n \n int recurr(vector<vector<int>>& grid , int row , int col){\n int n = grid.size();\n if(row >=n || col >=n ) return 0;\n \n if(mp[row][col] != -1){\n return mp[row][col];\n }\n int minn = INT_MAX;\n for(int...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n vector<int> prevRow(n);\n \n for(int j = 0; j < n; j++) {\n prevRow[j] = grid[0][j];\n }\n\n for(int i = 1; i < n; i++) {\n vector<int> ...
1,224
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p> <p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in...
3
{ "code": "class Solution {\npublic:\n pair<int,int> f(vector<int> a){\n sort(a.begin(),a.end());\n if(a.size()==1){\n return {a[0],a[0]};\n }\n return {a[0],a[1]};\n }\n int minFallingPathSum(vector<vector<int>>& grid) {\n int n=grid.size(),m=grid[0].size();\n ...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
0
{ "code": "class Solution {\npublic:\n int getDecimalValue(ListNode* head) {\n int result = 0;\n while(head) {\n result = result * 2 + head->val;\n head = head->next;\n }\n return result;\n }\n};\n", "memory": "9800" }
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
0
{ "code": "class Solution {\npublic:\n /**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode* next;\n * };\n */\n\nint getDecimalValue(struct ListNode* head) {\n struct ListNode* current = head;\n int length = 0;\n\n // Calculate the length of the linked...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
2
{ "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...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
2
{ "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...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
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...
1,411
<p>Given <code>head</code> which is a reference node to a singly-linked list. The value of each node in the linked list is either <code>0</code> or <code>1</code>. The linked list holds the binary representation of a number.</p> <p>Return the <em>decimal value</em> of the number in the linked list.</p> <p>The <strong...
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...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\n\n int numDigits(int n)\n {\n int res = 1;\n while (n /= 10)\n ++res;\n return res;\n }\n\n int getSequential(int numDigits, int offset = 0)\n {\n int res = 0;\n for (int i = 1; i <= numDigits; ++i)\n {\n res =...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n vector<int> sequentialDigits(int low, int high) {\n vector<int> ans;\n for (int i = 1; i < 9; ++i) {\n int num = i;\n int next = i + 1;\n\n while(num <= high && next <= 9) {\n num = num * 10 + next;\n ...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n vector<int> sequentialDigits(int low, int high) {\n vector<int> res {};\n queue<int> q;\n for(int i=1; i<9; i++) {\n q.push(i);\n }\n\n while(!q.empty()) {\n int top = q.front();\n q.pop();\n \n ...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n vector<int> sequentialDigits(int low, int high) {\n vector<int> res {};\n for(int i=1; i<=9; i++) {\n int num = i;\n for(int j=i+1; j<=9; j++) {\n num = (num * 10) + j;\n if(low <= num && num <= high) {\n ...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
0
{ "code": "class Solution {\npublic:\n int countDigits(int n){\n int t = 0;\n while(n>0){\n t++;\n n = n/10;\n }\n return t;\n }\n vector<int> sequentialDigits(int low, int high) {\n vector<int> ans;\n int a = countDigits(low);\n int b = ...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
1
{ "code": "class Solution {\npublic:\n vector<int> sequentialDigits(int low, int high) \n {\n string s=\"123456789\";\n vector<int>ans;\n\n for(int i=0;i<s.size();i++)\n {\n for(int j=i+1;j<=s.size();j++)\n {\n int curr=stoi(s.substr(i,j-i));\n\n ...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
1
{ "code": "class Solution {\npublic:\n vector<int> sequentialDigits(int low, int high) {\n std::vector<int> numbers;\n std::string digits = \"123456789\";\n \n for (int length = 2; length <= 9; length++) {\n for (int i = 0; i <= 9 - length; ++i) {\n // Substring give...
1,212
<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p> <p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p> <p>&nbsp;</p> <p><strong class="exa...
2
{ "code": "class Solution {\npublic:\n vector<int> sequentialDigits(int low, int high)\n {\n vector<int> result;\n string str = \"123456789\";\n\n int len = str.length();\n\n for (int i = 2; i <= len; i++) // start from 2 because low >= 10\n {\n for (int j = 0; j <=...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n\n int maxSumSubmatrix(vector<vector<int>>& matrix, int k) {\n\n int n = matrix.size();\n int m = matrix[0].size();\n\n vector<vector<int>>mat_m(n,vector<int>(m+1,0));\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n mat_m...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector<vector<int>>& matrix, int k) {\n int m = matrix.size(), n = matrix[0].size();\n int res = INT_MIN;\n vector<int> row_sum(m, 0);\n for (int l = 0; l < n; ++l)\n {\n fill(row_sum.begin(), row_sum.end(), 0)...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector<vector<int>>& matrix, int k) {\n int n=matrix.size();\n int m=matrix[0].size(); \n int ans=INT_MIN;\n for(int i=0;i<m;i++)\n {\n vector<int>sum(n,0);\n for(int r=i;r<m;r++)\n {\n ...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector<vector<int>>& matrix, int k) {\n\n if(matrix[0].size() > matrix.size()) {\n\n std::vector<int> rowSum(matrix[0].size());\n for(int i = 0; i < matrix.size(); ++i) {\n fill(rowSum.begin(), rowSum.end(), 0); ...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n \n int maxSumarray(vector<int>& A, int k){\n int sum = 0, res = INT_MIN;\n for(int a: A){\n sum += a;\n if(sum < a) sum = a;\n res = max(res, sum);\n if(res == k) return res;\n }\n // cout<< res << \" ...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n int subArraySumEqualsK(vector<int> &sum,int k){\n int n=sum.size();\n set<int> s;\n \n s.insert(0);\n \n int res= INT_MIN;\n int prefixSum=0;\n for(int i=0;i<n;i++){\n prefixSum+=sum[i];\n \n ...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector<vector<int>>& m, int k) {\n int res=INT_MIN,rows=m.size(),cols=m[0].size();\n for(int l=0;l<cols;++l){\n vector<int>sums(rows);\n for(int r=l;r<cols;++r){\n int kadane=0,max_kadane=INT_MIN;\n ...
363
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p> <p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p> <p...
1
{ "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector<vector<int>>& m, int k) {\n int res = INT_MIN, rows = m.size(), cols = m[0].size();\n for (int l = 0; l < cols; ++l) {\n vector<int> sums(rows);\n for (int r = l; r < cols; ++r) {\n int kadane = 0, max_kadane = INT...