forked from Shruti-codes/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlap.cpp
More file actions
32 lines (26 loc) · 706 Bytes
/
overlap.cpp
File metadata and controls
32 lines (26 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<vector>
using namespace std;
bool compare(vector<int>& f, vector<int>& s)
{
return (f[1] < s[1]);
}
int main()
{
vector<vector<int> > intervals{ {1,2},
{2,3},
{1,3} };
if(intervals.empty())
return 0;
int r=0, prev=0;
sort(intervals.begin(), intervals.end(), compare);
for(int i=1; i<intervals.size(); i++)
{
if(intervals[prev][1] > intervals[i][0])
r++;
else
prev = i;
}
cout<<r<<endl;
return 0;
}