Skip to content

Commit 0da77c6

Browse files
🔥 Day 4
1 parent 104284e commit 0da77c6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1. [Number of Recent Calls](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3480/) ➡️ [CPP Solution](Week1/RecentCounter.cpp)
1010
2. [Combination Sum](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3481/) ➡️ [CPP Solution](Week1/combinationSum.cpp)
1111
3. [K-diff Pairs in an Array](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3482/) ➡️ [CPP Solution](Week1/findPairs.cpp)
12+
4. [Remove Covered Intervals](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3482/) ➡️ [CPP Solution](Week1/removeCoveredIntervals.cpp)
1213

1314
## Week 2 🚧
1415

Week1/removeCoveredIntervals.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
static bool compare(vector<int> i1, vector<int> i2) {
4+
return i1[0] < i2[0];
5+
}
6+
7+
int removeCoveredIntervals(vector<vector<int>>& intervals) {
8+
int count = 0;
9+
int n = intervals.size();
10+
11+
if(n <= 1) return n;
12+
13+
sort(intervals.begin(), intervals.end(), compare);
14+
vector<int> curr = {-1, -1};
15+
16+
for(vector<int> in: intervals) {
17+
if(in[0] > curr[0] && in[1] > curr[1]) {
18+
count++;
19+
curr[0] = in[0];
20+
}
21+
22+
curr[1] = max(curr[1], in[1]);
23+
}
24+
25+
return count;
26+
}
27+
};

0 commit comments

Comments
 (0)