id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n // std::sort(intervals.begin(), intervals.end());\n\n std::sort(intervals.begin(), intervals.end(), [](const auto& a, const auto& b){return a[0] < b[0];});\n auto last = intervals.begin();\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic://[1-4] [2-3] \n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ret;\n ret.reserve(intervals.size());\n std::sort(intervals.begin(), intervals.end());\n \n ret.push_back(std::move(intervals[0]));\n\n fo...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic://[1-4] [2-3] \n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ret;\n ret.reserve(intervals.size());\n std::sort(intervals.begin(), intervals.end());\n \n ret.push_back(std::move(intervals[0]));\n\n fo...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic://[1-4] [2-3] \n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ret;\n ret.reserve(intervals.size());\n std::sort(intervals.begin(), intervals.end());\n \n ret.push_back(std::move(intervals[0]));\n\n fo...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n = intervals.size();\n sort(intervals.begin(), intervals.end());\n vector<vector<int>> output;\n output.reserve(intervals.size());\n\n for(auto& interval : intervals)\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) { \n sort(intervals.begin(), intervals.end());\n for(int i=0; i<intervals.size(); i++) {\n while(i+1<intervals.size() && intervals[i][1]>=intervals[i+1][0]) {\n intervals[...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n for(int i=0; i<intervals.size()-1;){\n if(intervals[i][1]>=intervals[i+1][0]){\n intervals[i][1]=max(intervals[i+1][1], int...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& v)\n {\n sort(v.begin(),v.end(),[](const vector<int> &a,const vector<int> &b){\n return a[0] < b[0];\n });\n bool correct = 0 ;\n while(correct == 0)\n {\n correct = 1;\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n int n = intervals.size();\n int res = 0;\n for(int i = 1; i < n; ++i){\n if(intervals[i][0] <= intervals[res][1]){\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n std::sort(intervals.begin(), intervals.end());\n \n std::vector<std::vector<int>> res;\n std::vector<int> prev = std::move(intervals[0]);\n\n for (std::size_t i = 1; i < intervals...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n std::sort(intervals.begin(), intervals.end(),\n [](const auto& a, const auto& b) {\n return a[0] < b[0];\n }\n );\n\n int len = static_cast<int>(intervals.s...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int i=0;\n sort(intervals.begin(),intervals.end());\n while(i<intervals.size()-1){\n if(intervals[i][1]>=intervals[i+1][0]){\n if(intervals[i][1]<intervals[i+1][1]){\n...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end());\n for(int i = 1; i<intervals.size(); i++) {\n if(intervals[i][0] <= intervals[i-1][1]) {\n intervals[i-1][1] = max(intervals[i][1]...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n=intervals.size();\n sort(intervals.begin(),intervals.end());\n int st=intervals[0][0];\n int end=intervals[0][1];\n vector<vector<int>> ans;\n bool flag=0;\n f...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n vector<vector<int>> output;\n output.push_back(intervals[0]);\n for(int i=1;i<intervals.size();i++){\n vector<int> &prev = output.ba...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n \n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(),intervals.end());\n\n vector<vector<int>> sol;\n\n sol.push_back(intervals[0]);\n int j=0;\n \n vector<int> b;\n for(int i=1;i<interval...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n \n sort(intervals.begin(), intervals.end());\n \n vector<vector<int>> Ans;\n \n int n = intervals.size();\n int start = intervals[0][0];\n int end = interval...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n vector<vector<int>> ans;\n int n=intervals.size();\n if(n==0)return ans;\n if(n==1) return intervals;\n vector<int>temp=intervals...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "bool compareBegin( vector<int>& vec1, vector<int> & vec2 )\n{\n return vec1.front() < vec2.front();\n}\n\nclass Solution\n{\npublic:\n vector<vector<int>> merge( vector<vector<int>> & intervals )\n {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n vector<vector<int>> resul...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> res;\n sort(intervals.begin(), intervals.end()); \n res.push_back(intervals[0]);\n for(int i = 1; i < intervals.size(); i++)\n {\n int start_i = res...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> res;\n sort(intervals.begin(),intervals.end());\n int l = intervals[0][0];\n int r = intervals[0][1];\n for(int i=1;i<intervals.size();i++){\n if(in...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n static bool compare(vector<int> &a, vector<int> &b){\n return a[0] < b[0];\n }\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end(), compare);\n stack<pair<int,int>> st;\n\n st.push({interval...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& inter) {\n sort(inter.begin(),inter.end());\n vector<vector<int>> ans;\n for(int i=0;i<inter.size();i++){\n if(ans.empty() || ans.back()[1]<inter[i][0]){\n ans.push_back(inter[i]);\n...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& arr) {\n vector<vector<int>> ans;\n sort(arr.begin(), arr.end());\n int n = arr.size();\n\n int start = arr[0][0];\n int end = arr[0][1];\n for(int i=1;i<n;i++){\n if(arr[i][0]...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n int n = intervals.size();\n if (n == 1) {\n return intervals;\n }\n int right = intervals[n-1][1];\n vector<vector<in...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& mat) {\n int n = mat.size();\n\n vector<pair<int, int>> vp;\n for (auto& it : mat){\n vp.push_back({it[0], it[1]});\n }\n\n sort(vp.begin(), vp.end());\n int cs = vp[0].first, ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n\n static bool cmp(vector<int>& a, vector<int>& b)\n {\n return a[0] < b[0];\n }\n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end(), cmp);\n if(intervals.size() == 1) return intervals;\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n \n using pii = pair<int, int>;\n priority_queue<pii, vector<pii>, greater<pii>> pq;\n for(int i = 0; i < intervals.size(); i++) {\n const auto& interval = intervals[i];\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n \n using pii = pair<int, int>;\n priority_queue<pii, vector<pii>, greater<pii>> pq;\n for(int i = 0; i < intervals.size(); i++) {\n const auto& interval = intervals[i];\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n \n\n \n sort(intervals.begin(),intervals.end());\n vector<int> temp = intervals[0];\n\n \n\n for(auto it : intervals)\n {\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end(), [](const vector<int>& a,const vector<int>& b){\n return a[0] < b[0];\n });\n\n int n = intervals.size();\n vector<vector<int>> ans;\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>>ans;\n if(intervals.size()==0)\n {\n return ans;\n }\n sort(intervals.begin(),intervals.end());\n vector<int>t=intervals[0];\n \n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n int n = intervals.size();\n vector<int> ni(2);\n int i=0;\n\n sort(intervals.begin(), intervals.end());\n for(auto it: intervals)\n for(au...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& arr) {\n sort(arr.begin(), arr.end());\n vector<vector<int>> ans;\n\n for (auto i : arr) {\n if (ans.empty() || ans.back()[1] < i[0])\n ans.push_back(i);\n else\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), intervals.end());\n vector<vector<int>> answer;\n vector<int> temp = intervals[0];\n for(auto interval : intervals){\n if(interval[0] <= temp[1]){\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end(), [](const vector<int>& a, const vector<int>& b) {\n return a[0] < b[0];\n });\n\n vector<vector<int>> merged;\n vector<int> prev = in...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n \n\n \n sort(intervals.begin(),intervals.end());\n vector<int> temp = intervals[0];\n\n \n\n for(auto it : intervals)\n {\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& inter) {\n // if(inter.size()==1) return inter;\n sort(inter.begin(),inter.end());\n vector<vector<int>> ans;\n int f=inter[0][0],s=inter[0][1];\n for(int i=0;i<inter.size()-1;i++){\n vector<int>...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n\n static bool cmp(pair<int,int> p1, pair<int,int> p2){\n if(p1.first==p2.first) return p1.second>p2.second;\n return p1.first<p2.first;\n }\n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<pair<int,int>> events;\n for(...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<int> res;\n\n sort(intervals.begin(), intervals.end());\n\n for(auto it : intervals) \n {\n if(res.empty() or res.back() < it[0]) res.push_back(it[0]), res.push_back(it...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n\n sort(intervals.begin(), intervals.end());\n\n int i = 1;\n while (i < intervals.size()) {\n vector<int> curr = intervals[i];\n vector<int> prev = intervals[i - 1];\n\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n=intervals.size();\n vector<vector<int> > arr ;\n\n sort(intervals.begin(),intervals.end());\n\n priority_queue<pair<int,int > > pq;\n\n for(int i=0;i<n;i++)\n {\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n int n=intervals.size();\n int flag=0;\n vector<vector<int>>ans;\n for(int i=0;i<n-1;i++){\n auto it=intervals[i];\n auto p=...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(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=0; i< intervals.size() ; i++){\n vector<int> temp = ans.back();\...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<int> mergeInterval(vector<int> A, vector<int> B) {\n return {A[0], max(A[1], B[1])};\n }\n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n = intervals.size();\n sort(intervals.begin(), intervals.end());\n\n vector...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<int> mergeInterval(vector<int> A, vector<int> B) {\n return {A[0], max(A[1], B[1])};\n }\n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n = intervals.size();\n sort(intervals.begin(), intervals.end());\n\n vector...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n = intervals.size();\n vector<pair<int, int>> inter;\n for (auto x : intervals) {\n inter.push_back({x[0], x[1]});\n }\n\n sort(inter.begin(), inter.end());\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n \n if(intervals.size()==1)\n return intervals;\n vector<pair<int,int>> p;\n for(int i=0;i<intervals.size();i++)\n {\n p.push_back({intervals[i][0],intervals[i][1]});\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int> &a,vector<int> &b)\n {\n if(a[1]==b[1])\n return a[0]<b[0];\n return a[1]<b[1];\n }\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),comp);\n sta...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n vector<pair<int, int>> nums;\n\n for(auto it:intervals){\n nums.push_back({it[0], it[1]});\n }\n\n sort(nums.begin(), nums.end());\n p...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n // [1,3]\n // [2,6]\n // [1,6]\n\n // cache up the interval {start, end} to dataMap\n // use the map lower_bound -> find the interval >= start\n\n vector<vector<int>> res;\...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> res;\n map<int, int> dataMap; // {start, end}\n\n for(auto &interval : intervals){\n int start = interval[0];\n int end = interval[1];\n\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n if(intervals.size() == 1){\n return intervals;\n }\n vector<vector<int>> ans;\n for(int i = 0 ;i< intervals.size(); i++){\n for(int j = 0 ;j< intervals.size(); j...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int pre=-1;\n sort(intervals.begin(),intervals.end());\n vector<vector<int>> ans;\n \n for(auto i: intervals){\n if(pre==-1 || ans[pre][1]<i[0]){\n ans.p...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n bool func(vector<int> i1,vector<int> i2){\n if(min(i1[1],i2[1])>=max(i1[0],i2[0])) return true;\n return false;\n }\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n vector<vector<in...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<pair<int,int>> temp;\n\n for(auto v:intervals){\n pair<int,int> p = {v[0],v[1]};\n temp.push_back(p);\n }\n sort(temp.begin(),temp.end());\n vector<ve...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution\n{\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals)\n {\n vector<vector<int>> result;\n\n sort(intervals.begin(), intervals.end());\n\n for (auto interval : intervals)\n {\n if (result.empty() || result.back()[1] < interval[0])...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n=intervals.size();\n sort(intervals.begin(),intervals.end());\n vector<vector<int>> ans;\n ans.push_back({intervals[0][0],intervals[0][1]});\n for(int i=1;i<n;i++){\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n map<int,int> m;\n for(auto interval : intervals){\n ++m[interval[0]];\n --m[interval[1]];\n }\n int cnt=0, prev = -1;\n boo...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<vector<int>> ans;\n vector<pair<int,int>> borders;\n for(auto v: intervals) {\n borders.push_back({v[0], -1});\n borders.push_back({v[1], 1});\n }\n\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<pair<int, bool>> points; //bool is whether it's a start\n for(auto x: intervals){\n points.push_back({x[0], true});\n points.push_back({x[1], false});\n }\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int>&a,vector<int>&b){\n return a[0]<b[0];\n }\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end(),comp);\n vector<vector<int>>ans;\n for(int i=0;i<intervals.size();i+...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(pair<int,int> a, pair<int,int> b){\n if(a.first!=b.first)\n return a.first<b.first;\n else \n return a.second<b.second;\n}\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<pair<int,int>>pairs;\n vector<vec...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(pair<int,int> a, pair<int,int> b){\n if(a.first!=b.first)\n return a.first<b.first;\n else \n return a.second<b.second;\n}\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<pair<int,int>>pairs;\n vector<vec...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(pair<int,int> a, pair<int,int> b){\n if(a.first!=b.first)\n return a.first<b.first;\n else \n return a.second<b.second;\n}\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n vector<pair<int,int>>pairs;\n vector<vec...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n=intervals.size();\n if(n==1)\n {\n return intervals;\n }\n sort(intervals.begin(),intervals.end());\n stack<vector<int>>q;\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n int n=intervals.size();\n if(n==1)\n {\n return intervals;\n }\n sort(intervals.begin(),intervals.end());\n stack<vector<int>>q;\n ...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n\n vector<vector<int>>res;\n res.push_back(intervals[0]);\n\n for(int i=1;i<intervals.size();i++)\n {\n auto prev = res.back()...
56
<p>Given an array&nbsp;of <code>intervals</code>&nbsp;where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return <em>an array of the non-overlapping intervals that cover all the intervals in the input</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:...
3
{ "code": "class Solution {\npublic:\n int min(int a, int b) {\n return a < b ? a : b;\n }\n int max(int a, int b) {\n return a < b ? b : a;\n }\n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n if (intervals.empty()) {\n return vector<vector<int>>();\n ...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\nstatic const bool __boost = []() {\n cin.tie(nullptr);\n cout.tie(nullptr);\n return std::ios_base::sync_with_stdio(false);\n }();\n\n\nconst size_t BUFFER_SIZE = 0x6fafffff;\nalignas(std::max_align_t...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& target) {\n const int n = intervals.size();\n if (n == 0) return {target};\n\n int x = 0, y = n-1;\n while (x <= y) {\n int mid = (x + y) >> 1;\n if (inte...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int len = static_cast<int>(intervals.size());\n\n std::vector<std::vector<int>> result;\n bool new_interval_added = false;\n int read_idx = 0;\n\n // Ta...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n \n int n = intervals.size();\n vector<vector<int>> ans;\n int start = newInterval[0];\n int end = newInterval[1];\n int i = 0;\n\n // exam...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int n=intervals.size();\n\n int i=0;//\n\n vector<vector<int>> res;\n\n while(i<n && intervals[i][1]<newInterval[0]){\n res.push_back(intervals[i]);...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "#include <vector>\r\n#include <algorithm>\r\nusing namespace std;\r\nclass Solution {\r\npublic:\r\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\r\n vector<vector<int>> Result;\r\n intervals.push_back(newInterval);\r\n sort(intervals.begin(...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "\nclass Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int n=intervals.size();\n\n int i=0;//\n\n vector<vector<int>> res;\n\n while(i<n && intervals[i][1]<newInterval[0]){\n res.push_back(intervals[i+...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n intervals.emplace_back(newInterval);\n return merge(intervals);\n }\n\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n sort(intervals.begin(), in...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& nums,vector<int>& ans) {\n vector<vector<int>>p;\n \n nums.push_back({ans[0],ans[1]});\n\n sort(nums.begin(),nums.end());\n\n int j=0;\n p.push_back({nums[0][0],nums[0][1]}...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int len = intervals.size();\n int leftVal = -1, rightVal = len;\n\n if (len == 0) {\n return {newInterval};\n }\n\n int l = -1, r = len, m;\n...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int len = intervals.size();\n int leftVal = -1, rightVal = len;\n\n if (len == 0) {\n return {newInterval};\n }\n\n // sef leftBound\n ...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n vector<vector<int>>res;\n int i=0;\n int n=intervals.size();\n while(i<n&& intervals[i][1]<newInterval[0]){\n res.push_back(intervals...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int n= intervals.size(),i=0;\n vector<vector<int>>res;\n\n \n while( i<n && newInterval[0]>intervals[i][1])\n {\n res.push_back(intervals[i]...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n vector<vector<int>> ans;\n // int s = min(intervals[0][0], newInterval[0][0]);\n // int e = max(intervals[0][1], newInterval[0][1]);\n\n int ns = newInterval[0...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "// Jai Shree Ram, Jai Hanuman Ji\n// 13 Sep 2024\n// Started: 06:08PM\n// Submitted: 06:45PM\nclass Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n vector<vector<int>> newIntervals;\n int n = intervals.size();\n int i = ...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int len = intervals.size();\n int leftVal = -1, rightVal = len;\n\n if (len == 0) {\n return {newInterval};\n }\n\n if (len == 1) {\n ...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n\n vector<vector<int>> merged = vector<vector<int>>{};\n\n vector<int> mergedInterval = newInterval;\n\n for(vector<int> interval : intervals){\n if(interva...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int n = intervals.size();\n vector<vector<int>> ans;\n if (n == 0) {\n ...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int n= intervals.size();\n int start=newInterval[0];\n int end= newInterval[1];\n int start_interval=-1;\n int end_interval=-1;\n vector<vector<i...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n vector<vector<int>> ans;\n for(auto it: intervals)\n {\n if(it[1]<newInterval[0]) ans.push_back(it);\n else if(newInterval[1]<it[0])\n ...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n vector<vector<int>> ans;\n int st = newInterval[0];\n int end = newInterval[1];\n bool isInserted = false;\n for(auto it:intervals){\n if(it[...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n intervals.push_back(newInterval);\n sort(intervals.begin(),intervals.end());\n\n vector<vector<int>> vv;\n for(auto v : intervals) {\n if (vv.empty(...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n if (intervals.size() == 0) {\n return {newInterval};\n }\n vector<vector<int>> ans;\n bool added = false;\n for (int i = 0; i < intervals.siz...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n intervals.push_back(newInterval);\n sort(intervals.begin(), intervals.end(), [](const vector<int>& a, const vector<int>& b) {\n return a[0] < b[0];\n });\n...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n intervals.push_back(newInterval);\n sort(intervals.begin(), intervals.end(), [](const vector<int>& a, const vector<int>& b) {\n return a[0] < b[0];\n });\n...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n\n static bool cmp(pair<int,int> p1, pair<int,int>p2){\n if(p1.first==p2.first) return p1.second>p2.second;\n return p1.first<p2.first;\n }\n\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n vector<pair<int,i...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n\n bool intersects(vector<int> a, vector<int> b){\n if(a[1]<b[0] || b[1]<a[0]) return false;\n return true;\n }\n\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int n=intervals.size();\n int newstart...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int start = newInterval[0], end = newInterval[1];\n vector<vector<int>> left, right;\n\n for(auto i:intervals){\n if(i[1]<start){\n left.pus...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\n\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n int start = newInterval[0], end = newInterval[1];\n vector<vector<int>> left, right;\n\n for(auto i:intervals){\n if(i[1]<start){\n left.p...
57
<p>You are given an array of non-overlapping intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represent the start and the end of the <code>i<sup>th</sup></code> interval and <code>intervals</code> is sorted in ascending order by <code>start<sub>i</sub></code>. You ...
3
{ "code": "class Solution {\npublic:\n\n bool isOverlapping(vector<int>& interval1, vector<int>& interval2) {\n if (interval1[0] < interval2[0]) {\n return interval2[0] >= interval1[0] && interval2[0] <= interval1[1];\n }\n return interval1[0] >= interval2[0] && interval1[0] <= inte...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n ofstream out(\"user.out\");\n\n char ch;\n bool flag = 0;\n bool start_s = 0;\n\n int max_size = -1;\n int cur_size = 0;\n int size = 0;\n \n\n cin.unsetf(ios_base::skipws);\n while (cin >> ch) {\n // c...