-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-119.cpp
43 lines (39 loc) · 1.07 KB
/
Day-119.cpp
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
33
34
35
36
37
38
39
40
41
42
43
//
// Created by Amit Kumar on 07/07/23.
//
#include "iostream"
#include "vector"
using namespace std;
vector<int> getSortestInterval(vector<vector<int>>&intervals) {
int start = intervals[0][1];
int end = start;
bool startFound = false;
for (int i=1; i < static_cast<int>(intervals.size()); ++i){
auto itr = intervals.at(i);
if (!startFound) {
if (itr.at(0) < start and itr.at(1) < start) {
start = itr.at(1);
} else {
startFound = true;
}
} else {
end = max(end, itr.at(0));
}
}
return {start, end};
}
int main() {
vector<vector<int>>intervals = {{0, 3},
{2, 6},
{3, 4},
{6, 9}
};
vector<int> res = getSortestInterval(intervals);
cout << res.at(0) << endl << res.at(1) << endl;
if (res.at(0) == 3 and res.at(1) == 6) {
cout << "passed" << endl;
} else {
cout << "failed" << endl;
}
return 0;
}