id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n int n=intervals.size();\n int i=0;\n int j=1;\n int cnt=0;\n while(j<n){\n vector<int>currinterval=intervals[i];\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n int ans =0;\n int i=0;\n int j=1;\n int n = intervals.size();\n while(j<n){\n auto curr = intervals[i];\n a...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int f(vector<vector<int>>& v,int n,int index,int first,int second,unordered_map<int,int>& dp){\n if(index == n)return 0;\n if(dp.find(index) != dp.end())return dp[index];\n if(v[index][0] < second){\n first = 1 + f(v,n,index+1,first,min...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>>v;\n for(int i = 0;i<intervals.size();i++){\n vector<int>temp;\n temp.push_back(intervals[i][1]);\n temp.push_back(intervals[i][0]);\n v....
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n int line = -1e9; \n vector<vector<int>> v; \n for(auto it: intervals) {\n // v.push_back({it[0], -1}); \n v.push_back({it[1], it[0]}); \n }\n sort(v.begin(),...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>> vec;\n for(auto i: intervals){\n vec.push_back({i[1], i[0]});\n }\n \n sort(vec.begin(), vec.end());\n \n \n int count = 1;\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> mIntervals;\n\n std::vector<int> dp;\n int solve(int n) {\n if(n >= mIntervals.size()) return 0;\n\n auto start = mIntervals[n][0];\n auto end = mIntervals[n][1];\n\n int & memo = dp[n];\n\n if(memo != -1) return me...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int>&a,vector<int>&b){\n return a[0]<b[0];\n }\n int eraseOverlapIntervals(vector<vector<int>>& inter) {\n sort(inter.begin(),inter.end(),cmp);\n vector<vector<int>>ans;\n int n=inter.size();\n ans.push_back(in...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "bool cmp(vector<int> &a, vector<int> &b){\n return a[0] < b[0];\n}\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) { \n\n sort(intervals.begin(), intervals.end(), cmp);\n int ans = 0;\n int n = intervals.size();\n\n stack<vector<int> ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& i) {\n sort(i.begin(), i.end(),[&](vector<int> &i, vector<int> &j) {\n return i[1] < j[1];\n });\n vector<vector<int>>dp;\n for(int j=0; j<i.size(); j++){\n dp.push_back({i[j][0], -1});\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n\n bool is_overlapping(vector<int> interval1, vector<int> interval2) {\n return interval1[1] > interval2[0];\n }\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n stack<vector<int>> st;\n sort(intervals.begin(), intervals.end());\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) \n {\n int count =0;\n std::sort(intervals.begin(), intervals.end(), [](const std::vector<int>& a, const std::vector<int>& b) {\n return a[1] < b[1];\n });\n unordered_map<int,i...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>> sortedIntervals;\n vector<vector<int>> esIntervals;\n for (auto i: intervals) esIntervals.push_back({i[1], i[0]});\n sort(esIntervals.begin(), esIntervals.end());\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>> v;\n int n= intervals.size(),i, maxm = 0;\n vector<int> dp(n+1, 0);\n int ind=0;\n for(auto x: intervals){\n v.push_back({x[0], 1, ind});\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>> v;\n int n= intervals.size(),i, maxm = 0;\n vector<int> dp(n+1, 0);\n int ind=0;\n for(auto x: intervals){\n v.push_back({x[0], 1, ind});\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n map<int,multiset<int>>s;\n\n for(auto v:intervals) s[v[0]].insert(v[1]);\n\n multiset<int>S;int val=0;\n for(auto v:s) {\n while(S.size()&&*S.begin()<=v.first)S.erase(S.begin(...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n //dp\n //sort by end dates\n sort(intervals.begin(), intervals.end(), \n [&](vector<int>& l,vector<int>& r){\n return l[1]<r[1];\n });\n\n // map<int...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<vector<int>> sp(100001);\n vector<int> dp(100001);\n\n for(int i=0;i<intervals.size();i++) {\n sp[intervals[i][1] + 50000].push_back(intervals[i][0] + 50000);\n }\n\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": " int heapsize;\nclass Solution {\npublic:\n\n\n void MaxHeapify(vector<vector<int>> &A,int i){\n\n int l =2*i+1;\n int r =2*i+2;\n int largest=i;\n\n if(l<heapsize && A[l][1] > A[largest][1]){\n largest=l;\n }\n\n if(r<heapsize && A[r][1] > A[largest]...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n auto endsHere = vector<vector<int>>(100001, vector<int>());\n\n for (auto interval : intervals) {\n endsHere[interval[1] + 50000].push_back(interval[0] + 50000);\n }\n\n auto ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "bool comp(vector<int> &a, vector<int> b) {\n return a[1] < b[1];\n}\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end(), comp);\n int end_time = intervals[0][1];\n int count = 0;\n for (int i = ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "using namespace std;\nclass Solution {\npublic:\n static bool cmp(vector<int>& a,vector<int> b){\n return a[1] < b[1];\n }\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n \n sort(intervals.begin(),intervals.end(),cmp);\n\n int count = 0;\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n struct Data{\n int start;\n int end;\n };\n bool static comp(vector<int>&v1 ,vector<int>v2){\n return v1[1]<v2[1];\n }\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n int ans=1;\n int n=intervals.size();\n ...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "\n bool sortIntervals(vector<int> & a1, vector<int> a2){\n return (a1[0]< a2[0]);\n }\n\nclass Solution {\npublic:\n\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end(), sortIntervals);\n\n int count=0;\n int prev_...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "\n bool sortIntervals(vector<int> & a1, vector<int> a2){\n return (a1[0]< a2[0]);\n }\n\nclass Solution {\npublic:\n\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end(), sortIntervals);\n\n int count=0;\n int prev_...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "\n bool sortIntervals(vector<int> & a1, vector<int> a2){\n return (a1[0]< a2[0]);\n }\n\nclass Solution {\npublic:\n\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end(), sortIntervals);\n\n int count=0;\n int prev_...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "\n bool sortIntervals(vector<int> & a1, vector<int> a2){\n return (a1[0]< a2[0]);\n }\n\nclass Solution {\npublic:\n\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end(), sortIntervals);\n\n int count=0;\n int prev_...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& i) {\n sort(i.begin(), i.end(), [&](vector<int>& a, vector<int>b){\n if(a[1]==b[1]){\n return a[0]<b[0];\n }\n return a[1]<b[1];\n });\n int c = 0, n = i.size()...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n static int cmp(const vector<int>&a, const vector<int>b){\n if(a[0]==b[0]) return a[1]<b[1];\n else return a[0]<b[0]; \n }\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),cmp);\n int...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\nstatic bool comp(vector<int > v1, vector<int > v2){\n return v1[1] < v2[1];\n}\n int eraseOverlapIntervals(vector<vector<int>>& arr) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n = arr.size();\n sort(arr.begin(), arr.end(), com...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n static bool mycmp(vector<int> f, vector<int> s){\n return f[1] < s[1];\n }\n int eraseOverlapIntervals(vector<vector<int>>& interval) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n = interval.size();\n sort(interval....
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "bool compare(vector<int> a, vector<int> b){\n return a[1] < b[1];\n}\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n sort(intervals.begin(), intervals.en...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n std::ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n\n if (intervals.empty()) return 0;\n // Sort the intervals based on end time, and then it helps t...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int> a,vector<int> b){\n return a[1]<b[1];\n }\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n // remove minima overlapping, \n // i.e have maximum intervals/ meetings\n sort(intervals.begin(),intervals...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n\n bool static comparator(vector <int> a, vector <int> b)\n {\n if (a[1] < b[1]) return true;\n return false;\n }\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) \n {\n\n int n = intervals.size();\n\n sort (intervals.begin(...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int>a,vector<int>b)\n {\n return a[1] < b[1];\n }\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),comp);\n int cnt=1,freeTime=intervals[0][1];\n for(int i = 1...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "bool compare(vector<int>a,vector<int>b){\n return a.back()<b.back();\n}\n\n\n\n\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(),intervals.end(),compare);\n\n int j=intervals[0].size();\n int count=0;\n\n i...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n\n static bool compare(vector<int> a, vector<int> b) {\n return a[1] < b[1];\n }\n\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end(), compare);\n int count = 0;\n int prev_end = intervals[0...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "bool compare(vector<int>a,vector<int>b){\n return a.back()<b.back();\n}\n\n\n\n\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(),intervals.end(),compare);\n\n int j=intervals[0].size();\n int count=0;\n\n i...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\n bool static comp(vector<int> a, vector<int> b)\n {\n return a[1] < b[1];\n }\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n int n = intervals.size();\n\n sort(intervals.begin(), intervals.end(), comp);\n\n int hi = INT_MIN...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "// miss\n// This sorting is crucial because it allows us to prioritize intervals that finish early, giving us more opportunities to accommodate additional meetings later on.\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n // This sorting is crucial bec...
435
<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre>...
3
{ "code": "class Solution {\npublic:\nstruct compare{\n bool operator()(const vector<int> a, const vector<int> b){\n return a[1] < b[1];\n }\n};\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n if (intervals.size() == 0) {\n return 0;\n }\n sort(intervals...
1,236
<p>The Tribonacci sequence T<sub>n</sub> is defined as follows:&nbsp;</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n &gt;= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p>&nbsp;</p> <p><strong cla...
0
{ "code": "class Solution {\npublic:\n int tribonacci(int n) {\n if (n < 2) return n;\n else if (n == 2) return 1;\n\n int a = 0;\n int b = 1;\n int c = 1;\n int ans;\n\n for (int i = 2; i < n; i++)\n {\n ans = a + b + c;\n a = b;\n ...
1,236
<p>The Tribonacci sequence T<sub>n</sub> is defined as follows:&nbsp;</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n &gt;= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p>&nbsp;</p> <p><strong cla...
0
{ "code": "class Solution {\npublic:\n int tribonacci(int n) {\n if (n <= 1)\n return n;\n\n int prev3 = 0, prev2 = 1, prev = 1;\n for (int i = 3; i <= n; i++) {\n int curr = prev3 + prev2 + prev;\n\n prev3 = prev2;\n prev2 = prev;\n prev ...
1,236
<p>The Tribonacci sequence T<sub>n</sub> is defined as follows:&nbsp;</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n &gt;= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p>&nbsp;</p> <p><strong cla...
1
{ "code": "class Solution {\npublic:\n int tribonacci(int n) {\n\n if (n == 0) return 0;\n if (n == 1 || n == 2) return 1;\n\n vector<int> dp(n+1, 0);\n dp[0] = 0;\n dp[1] = dp[2] = 1;\n for(int i=3;i<=n;i++)\n dp[i] = dp[i-1] + dp[i-2] + dp[i-3];\n\n return ...
1,236
<p>The Tribonacci sequence T<sub>n</sub> is defined as follows:&nbsp;</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n &gt;= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p>&nbsp;</p> <p><strong cla...
1
{ "code": "class Solution {\npublic:\n Solution() {\n m_tribonacci[0] = 0;\n m_tribonacci[1] = 1;\n m_tribonacci[2] = 1;\n\n for(short i = 3; i < 38; i++) {\n m_tribonacci[i] = m_tribonacci[i - 3] + m_tribonacci[i - 2] + m_tribonacci[i - 1];\n }\n }\n\n int tribo...
1,236
<p>The Tribonacci sequence T<sub>n</sub> is defined as follows:&nbsp;</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n &gt;= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p>&nbsp;</p> <p><strong cla...
2
{ "code": "class Solution {\npublic:\n int bottomUp(int n) {\n if(n==0){return 0;}\n if(n<3) {return 1;}\n vector<int> dp(n + 1, 0);\n dp[1] = 1;\n dp[2] = 1;\n for (int i = 3; i < n+1; i++) {\n dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];\n }\n return dp[n];\n }\n int tribonacci(int n) ...
1,236
<p>The Tribonacci sequence T<sub>n</sub> is defined as follows:&nbsp;</p> <p>T<sub>0</sub> = 0, T<sub>1</sub> = 1, T<sub>2</sub> = 1, and T<sub>n+3</sub> = T<sub>n</sub> + T<sub>n+1</sub> + T<sub>n+2</sub> for n &gt;= 0.</p> <p>Given <code>n</code>, return the value of T<sub>n</sub>.</p> <p>&nbsp;</p> <p><strong cla...
2
{ "code": "class Solution {\npublic:\n int lol(int n, vector<int> &dp){\n if(n==0) return 0;\n if(n==1 || n==2) return 1;\n\n if(dp[n]!=-1) return dp[n];\n\n return dp[n] = lol(n-1, dp) + lol(n-2, dp) + lol(n-3, dp); \n }\n int tribonacci(int n) {\n vector<int> dp(n+1, -1);...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC optimize(\"no-math-errno,unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\n\nstatic const auto init = [](){\n cin.tie(nullptr);\n cout.tie(nullptr);\n ios_base::sync_with_stdio(false);\n\n return -1;\n}();\n\nclass...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n \n int n = text1.size();\n int m = text2.size();\n int dp[2][m+1];\n memset(dp, 0, sizeof(dp));\n for(int i=1; i<=n; i++) {\n for(int j=1; j<=m; j++) {\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int n=text1.size();\n int m=text2.size();\n vector <int>curr(m+1,0),prev(m+1,0);\n for(int indx1=1;indx1<=n;indx1++){\n for(int indx2=1;indx2<=m;indx2++){\n if(t...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int a[2][1024] = {};\n\n for (int i = 0; i < text1.length(); i++) {\n for (int j = 0; j < text2.length(); j++) {\n a[(i+1)&1][j+1] = a[i&1][j];\n if (text1[i] =...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "// class Solution {\n// public:\n// int solve(string &a, string &b, int i, int j,vector<vector<int>> &dp){\n// int n = a.length();\n// int m = b.length();\n// if(j>=m || i>=n) {\n// return 0;\n// }\n// // else \n// if(dp[i][j]!=-1){\n// ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\nint binarySearchReplace(vector<int>& seq, int pos) {\n int low = 0, high = seq.size();\n while (low < high) {\n int mid = low + (high - low) / 2;\n if (seq[mid] < pos)\n low = mid + 1;\n else\n high = mid;\n }\n return low;\n...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n \n int m=text1.size();\n int n=text2.size();\n int maxi=0;\n unordered_map<int , int > map;\n for(int i=m-1 ; i>=0 ; i--)\n {\n //int max=0;\n i...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string &a, string &b) {\n short m[1001][1001] = {};\n for (auto i = 0; i < a.size(); ++i){\n for (auto j = 0; j < b.size(); ++j){\n if(a[i]==b[j]){\n m[i+1][j+1]=m[i][j]+1;\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution\n{\npublic:\n int longestCommonSubsequence(const std::string &text1, const std::string &text2)\n {\n uint16_t rows = text1.length() + 1,\n cols = text2.length() + 1,\n x, y,\n acc = 0;\n\n uint16_t matrix[rows][cols];\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string& a, string& b) {\n short m[1001][1001] = {};\n for (auto i = 0; i < a.size(); ++i)\n for (auto j = 0; j < b.size(); ++j)\n m[i + 1][j + 1] =\n a[i] == b[j] ? m[i][j] + 1 : max(m[i +...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string& a, string& b) {\n short m[1001][1001] = {};\n for (auto i = 0; i < a.size(); ++i)\n for (auto j = 0; j < b.size(); ++j)\n m[i + 1][j + 1] =\n a[i] == b[j] ? m[i][j] + 1 : max(m[i +...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string a, string b) {\n short m[1001][1001] = {};\n for (auto i = 0; i < a.size(); ++i)\n for (auto j = 0; j < b.size(); ++j)\n m[i + 1][j + 1] = a[i] == b[j] ? m[i][j] + 1 : max(m[i + 1][j], m[i][j + 1]);\n...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "const int N = 1002;\nint dp[N][N] = {-1};\nclass Solution {\npublic:\n int calc(string& s1, string& s2, int i, int j) {\n //cout << \"i: \"<<i << \" j: \"<<j <<endl;\n if (i >= s1.size() || j >= s2.size()) return 0;\n if (dp[i][j]!=-1)return dp[i][j];\n //cout << \"new\" <<e...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "int dp[1001][1001];\nclass Solution {\npublic:\n int LCS(string& x, string& y, int n, int m) {\n\n for (int i = 0; i <= n; i++) {\n dp[i][0] = 0;\n }\n for (int i = 0; i <= m; i++) {\n dp[0][i] = 0;\n }\n\n for (int i = 1; i <= n; i++) {\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n static int dp[1001][1001];\n int longestCommonSubsequence(string text1, string text2) {\n int n = text1.size();\n int m = text2.size();\n\n memset(dp, 0, sizeof(dp));\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "string str1 , str2;\nconst int MX2=1000+1;\nint memo3[MX2][MX2];\nint LSC (int i , int j)\n{\n if (i == (int) str1.size() || j == (int) str2.size())\n return 0;\n\n auto &ret = memo3[i][j];\n if (ret != -1)\n return ret;\n if (str1[i]==str2[j])\n return ret= 1 + LSC(i+1,j+1...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n\n int n1=text1.length(), n2=text2.length(), table[n1+1][n2+1];\n for(int i=0;i<=n1;i++)\n {\n table[i][0]=0;\n }\n for(int j=0;j<=n2;j++)\n {\n table[0...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string t1, string t2) {\n int m = t1.length(), n = t2.length();\n int dp[m+1][n+1];\n for (int i=0; i<=m; i++){\n dp[i][0] = 0;\n }\n for (int j=0; j<=n; j++){\n dp[0][j] = 0;\n }\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n \n int m = text1.length();\n int n = text2.length();\n int t[m+1][n+1];\n\n for(int i=0; i<m+1; i++){\n for(int j=0; j<n+1; j++){\n if(i==0 || j==0){\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.length();\n int n = text2.length();\n int dp[m+1][n+1];\n for(int k=0 ; k<=n ; k++)\n dp[0][k] = 0;\n for(int k=0 ; k<=m ; k++)\n dp[k][0] = 0;\...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n\n int n = text1.length();\n int m = text2.length();\n\n int dp[n+1][m+1];\n for(int i=0;i<=n;i++){\n dp[i][0] = 0;\n } \n for(int i=0;i<=m;i++){\n dp...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n\n int longestCommonSubsequence(string text1, string text2) {\n int dp[text1.size() + 1][text2.size() + 1];\n for (int i = 0; i <= text1.size(); i++) {\n dp[i][0] = 0;\n }\n for (int i = 0; i <= text2.size(); i++) {\n dp[0][i] ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.length(), n = text2.length();\n int dp[m+1][n+1];\n for(int i=0;i<=m;i++){\n dp[i][0] = 0;\n } \n for(int i=0;i<=n;i++){\n dp[0][i] = 0;\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n string text1_, text2_;\n int dp[1000][1000];\n bool seen[1000][1000];\n\n int lcs(int i, int j) {\n if (i < 0 || j < 0)\n return 0;\n if (seen[i][j])\n return dp[i][j];\n \n seen[i][j] = true;\n // cout << i << \" \" <<...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "int n,m;\nstring s1,s2;\nint dp[1001][1001];\n\nint rec(int i, int j){\n //pruning\n //base\n if(i==n||j==m)return 0;\n //cache check\n if(dp[i][j]!=-1)return dp[i][j];\n //calculate\n int ans=0;\n \n \n ans=max({ans,rec(i+1,j),rec(i,j+1)});\n if(s1[i]==s2[j]){ans=max(ans,...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int lcs(string a,string b,int m, int n){\n int mat[m+1][n+1];\n for(int i=0;i<=m;i++){\n for(int j=0;j<=n;j++){\n if(i==0 || j==0){\n mat[i][j]=0;\n }\n else if(a[i-1]==b[j-1]){\n mat[i][j]=1+ma...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int dp[1001][1001];\n int helper(int i, int j, string& a, string& b) {\n if (i >= a.size() || j >= b.size()) {\n return 0;\n }\n if (dp[i][j] != -1) {\n return dp[i][j];\n }\n int ok = 0, skip1 = 0, skip2 = 0;\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int dp[1001][1001];\n int helper(int i, int j, string& a, string& b) {\n if (i >= a.size() || j >= b.size()) {\n return 0;\n }\n if (dp[i][j] != -1) {\n return dp[i][j];\n }\n int ok = 0, skip1 = 0, skip2 = 0;\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "// class Solution {\n// public:\n// int dp[1001][1001];\n// // int find(string &s,string &t,int n,int m,int i,int j){\n// // if(i>=n || j>=m){\n// // return 0;\n// // }\n// // if(dp[i][j]!=-1){\n// // return dp[i][j];\n// // }\n// // i...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int dp[1001][1001];\n int helper(int i, int j, string &text1, string &text2, int m, int n) {\n if(i>=m || j>=n) return 0;\n int pick = 0;\n\n if(dp[i][j]!=-1) return dp[i][j];\n if(text1[i] == text2[j]) {\n pick = 1 + helper(i+1, j+1,...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<short> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = valu...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<short> memo;\n short* memo1;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n memo1 = memo.data();\n }\n int memoSet(int size1, int size2, int value) ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<short> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = valu...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<short> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = valu...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<short> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = valu...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<short> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = valu...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\nmap<char,vector<int>>mp;\n int longestCommonSubsequence(string A, string B) {\n for(int i=0; i<B.size(); i++){\n mp[B[i]].push_back(i);\n }\n vector<int>ans;\n for(auto it:A){\n if(mp.find(it)!=mp.end()){\n vecto...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n map<char, vector<int>> mp;\n \n int longestCommonSubsequence(string A, string B) {\n // Step 1: Map the positions of each character in string B\n for (int i = 0; i < B.size(); i++) {\n mp[B[i]].push_back(i);\n }\n\n vector<int> ans...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "#define ll long long int\nconst int N=1001;\nll dp[N][N];\nstring a,b;\nll n,m,mx;\n\nclass Solution {\npublic:\nll solve(ll i,ll j){\n if(i>=n||j>=m)return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n if(a[i]==b[j]){\n return dp[i][j]=1+solve(i+1,j+1);\n }\n ll ans=0;\n ans=max(ans,sol...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int helper(string text1, string text2, int n, int m){\n if(n == 0|| m == 0)\n return 0;\n\n if(text1[n-1] == text2[m-1])\n return 1 + helper(text1, text2, n-1, m-1);\n else\n return max(helper(text1, text2, n-1, m) , helpe...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int arr[1000][1000]={-1};\n int function(string& text1,string& text2,int ind1,int ind2)\n {\n if(ind1>=text1.length() or ind2>= text2.length())\n return 0;\n if(arr[ind1][ind2]!=-1)\n return arr[ind1][ind2];\n if(text1[ind1] ==...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string str1, string str2) {\n long long dp[str1.size()+1][str2.size()+1];\n for (int i = 0; i <= str1.size(); i++){\n dp[i][0] = 0;\n }\n for (int i = 0; i <= str2.size(); i++){\n dp[0][i] = 0;\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n \n int longestCommonSubsequence(string text1, string text2) {\n if (text1.empty() || text2.empty()) {\n return 0;\n }\n\n short **dp = new short*[text1.length()];\n for (int i = 0; i < text1.length(); ++i) {\n dp[i] = new s...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n \n int longestCommonSubsequence(string text1, string text2) {\n if (text1.empty() || text2.empty()) {\n return 0;\n }\n\n short **dp = new short*[text1.length()];\n for (int i = 0; i < text1.length(); ++i) {\n dp[i] = new s...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n \n int longestCommonSubsequence(string text1, string text2) {\n if (text1.empty() || text2.empty()) {\n return 0;\n }\n\n short **dp = new short*[text1.length()];\n for (int i = 0; i < text1.length(); ++i) {\n dp[i] = new s...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n \n int longestCommonSubsequence(string text1, string text2) {\n if (text1.empty() || text2.empty()) {\n return 0;\n }\n\n short **dp = new short*[text1.length()];\n for (int i = 0; i < text1.length(); ++i) {\n dp[i] = new s...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n typedef unsigned short DT;\n int longestCommonSubsequence(string text1, string text2) {\n vector<vector<DT>> lcs(text1.size()+1, vector<DT>(text2.size()+1, 0));\n for (DT i=0; i < text1.size(); i++) {\n for (DT j=0; j < text2.size(); j++) {\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n typedef unsigned short DT;\n int longestCommonSubsequence(string text1, string text2) {\n vector<vector<DT>> lcs(text1.size()+1, vector<DT>(text2.size()+1, 0));\n for (DT i=0; i < text1.size(); i++) {\n for (DT j=0; j < text2.size(); j++) {\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n int dp[1500][1500];\n\n int helper(string& text1, string& text2, int i, int j) {\n if (i < 0 || j < 0)\n return 0;\n\n if (dp[i][j] != -1)\n return dp[i][j];\n\n if (text1[i] == text2[j]) {\n dp[i][j] = 1 + helper(text1, text2, ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n // int solve(string& text1, string& text2, int m, int n, int i, int j,vector<vector<int>>&dp){\n // if(i==m)return 0;\n // if(j==n)return 0;\n // if(dp[i][j]!=-1)return dp[i][j];\n // int ans=0;\n // if(text1[i]==text2[j]){\n // a...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.size();\n int n = text2.size();\n\n // Brute-force n^2 approach -> getting TLE\n // vector<vector<int>> dp(m+1, vector<int>(n+1, 0));\n\n // for(int i=1; i<=m; i++){\...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.size();\n int n = text2.size();\n\n // Brute-force n^2 approach -> getting TLE\n // vector<vector<int>> dp(m+1, vector<int>(n+1, 0));\n\n // for(int i=1; i<=m; i++){\...