Skip to content

Commit 27d4809

Browse files
🔥 Day 27
1 parent 49c270f commit 27d4809

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
1. [Random Point in Non-overlapping Rectangles](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3433/) ➡️ [CPP Solution](Week4/randomPoint.cpp)
4040
2. [Stream of Characters](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3434/) ➡️ [CPP Solution](Week4/streamChecker.cpp)
4141
3. [Sum of Left Leaves](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3435/) ➡️ [CPP Solution](Week4/sumOfLeftLeaves.cpp)
42-
4. [Minimum Cost For Tickets](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3435/) ➡️ [CPP Solution](Week4/mincostTickets.cpp)
43-
5. [Fizz Buzz](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3435/) ➡️ [CPP Solution](Week4/fizzBuzz.cpp)
42+
4. [Minimum Cost For Tickets](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3436/) ➡️ [CPP Solution](Week4/mincostTickets.cpp)
43+
5. [Fizz Buzz](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3437/) ➡️ [CPP Solution](Week4/fizzBuzz.cpp)
44+
6. [Find Right Interval](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/552/week-4-august-22nd-august-28th/3438/) ➡️ [CPP Solution](Week4/findRightInterval.cpp)
4445

4546
## Week 5 🚧
4647

Week4/findRightInterval.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
vector<int> findRightInterval(vector<vector<int>>& intervals) {
4+
map<int, int> m;
5+
vector<int> result;
6+
int n = intervals.size();
7+
8+
if(n == 0) return {};
9+
if(n == 1) return {-1};
10+
11+
for(int i = 0; i < n; ++i) {
12+
int start = intervals[i][0];
13+
m[start] = i;
14+
}
15+
16+
for(int i = 0; i < n; ++i) {
17+
int end = intervals[i][1];
18+
auto it = m.lower_bound(end);
19+
20+
int index = it != m.end() ? it -> second : -1;
21+
result.push_back(index);
22+
}
23+
24+
return result;
25+
}
26+
};

0 commit comments

Comments
 (0)