feat: populate note files with problem descriptions and code stubs
Add populate-notes.mjs that fetches problem descriptions and Python/C++ code stubs from LeetCode's GraphQL API. Populated all 197 NeetCode 150 note files with: - Problem description (examples, constraints) - Python code stub (function signature) - C++ code stub (function signature + includes) API responses cached in leetcode/.cache/leetcode/ for instant re-runs.
This commit is contained in:
@@ -1,18 +1,64 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0056. Merge Intervals :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0056. Merge Intervals][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0056. Merge Intervals][0056. Merge Intervals]]
|
||||
:END:
|
||||
|
||||
Given an array of ~intervals~ where ~intervals[i] = [start_{i}, end_{i}]~, merge all overlapping intervals, and return /an array of the non-overlapping intervals that cover all the intervals in the input/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
|
||||
Output: [[1,6],[8,10],[15,18]]
|
||||
Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,4],[4,5]]
|
||||
Output: [[1,5]]
|
||||
Explanation: Intervals [1,4] and [4,5] are considered overlapping.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[4,7],[1,4]]
|
||||
Output: [[1,7]]
|
||||
Explanation: Intervals [1,4] and [4,7] are considered overlapping.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= intervals.length <= 10^{4}~
|
||||
|
||||
- ~intervals[i].length == 2~
|
||||
|
||||
- ~0 <= start_{i} <= end_{i} <= 10^{4}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<vector<int>> merge(vector<vector<int>>& intervals) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,65 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0057. Insert Interval :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0057. Insert Interval][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0057. Insert Interval][0057. Insert Interval]]
|
||||
:END:
|
||||
|
||||
You are given an array of non-overlapping intervals ~intervals~ where ~intervals[i] = [start_{i}, end_{i}]~ represent the start and the end of the ~i^{th}~ interval and ~intervals~ is sorted in ascending order by ~start_{i}~. You are also given an interval ~newInterval = [start, end]~ that represents the start and end of another interval.
|
||||
|
||||
Insert ~newInterval~ into ~intervals~ such that ~intervals~ is still sorted in ascending order by ~start_{i}~ and ~intervals~ still does not have any overlapping intervals (merge overlapping intervals if necessary).
|
||||
|
||||
Return ~intervals~/ after the insertion/.
|
||||
|
||||
*Note* that you don't need to modify ~intervals~ in-place. You can make a new array and return it.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
|
||||
Output: [[1,5],[6,9]]
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
|
||||
Output: [[1,2],[3,10],[12,16]]
|
||||
Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~0 <= intervals.length <= 10^{4}~
|
||||
|
||||
- ~intervals[i].length == 2~
|
||||
|
||||
- ~0 <= start_{i} <= end_{i} <= 10^{5}~
|
||||
|
||||
- ~intervals~ is sorted by ~start_{i}~ in *ascending* order.
|
||||
|
||||
- ~newInterval.length == 2~
|
||||
|
||||
- ~0 <= start <= end <= 10^{5}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0252. Meeting Rooms :easy:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0252. Meeting Rooms][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0252. Meeting Rooms][0252. Meeting Rooms]]
|
||||
:END:
|
||||
|
||||
** TODO Approach
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0253. Meeting Rooms II :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0253. Meeting Rooms II][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0253. Meeting Rooms II][0253. Meeting Rooms II]]
|
||||
:END:
|
||||
|
||||
** TODO Approach
|
||||
|
||||
@@ -1,18 +1,66 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0435. Non Overlapping Intervals :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0435. Non Overlapping Intervals][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0435. Non Overlapping Intervals][0435. Non Overlapping Intervals]]
|
||||
:END:
|
||||
|
||||
Given an array of intervals ~intervals~ where ~intervals[i] = [start_{i}, end_{i}]~, return /the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping/.
|
||||
|
||||
*Note* that intervals which only touch at a point are *non-overlapping*. For example, ~[1, 2]~ and ~[2, 3]~ are non-overlapping.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,2],[2,3],[3,4],[1,3]]
|
||||
Output: 1
|
||||
Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,2],[1,2],[1,2]]
|
||||
Output: 2
|
||||
Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,2],[2,3]]
|
||||
Output: 0
|
||||
Explanation: You don't need to remove any of the intervals since they're already non-overlapping.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= intervals.length <= 10^{5}~
|
||||
|
||||
- ~intervals[i].length == 2~
|
||||
|
||||
- ~-5 * 10^{4} <= start_{i} < end_{i} <= 5 * 10^{4}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,64 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0986. Interval List Intersections :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0986. Interval List Intersections][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0986. Interval List Intersections][0986. Interval List Intersections]]
|
||||
:END:
|
||||
|
||||
You are given two lists of closed intervals, ~firstList~ and ~secondList~, where ~firstList[i] = [start_{i}, end_{i}]~ and ~secondList[j] = [start_{j}, end_{j}]~. Each list of intervals is pairwise *disjoint* and in *sorted order*.
|
||||
|
||||
Return /the intersection of these two interval lists/.
|
||||
|
||||
A *closed interval* ~[a, b]~ (with ~a <= b~) denotes the set of real numbers ~x~ with ~a <= x <= b~.
|
||||
|
||||
The *intersection* of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of ~[1, 3]~ and ~[2, 4]~ is ~[2, 3]~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]
|
||||
Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: firstList = [[1,3],[5,9]], secondList = []
|
||||
Output: []
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~0 <= firstList.length, secondList.length <= 1000~
|
||||
|
||||
- ~firstList.length + secondList.length >= 1~
|
||||
|
||||
- ~0 <= start_{i} < end_{i} <= 10^{9}~
|
||||
|
||||
- ~end_{i} < start_{i+1}~
|
||||
|
||||
- ~0 <= start_{j} < end_{j} <= 10^{9} ~
|
||||
|
||||
- ~end_{j} < start_{j+1}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<vector<int>> intervalIntersection(vector<vector<int>>& firstList, vector<vector<int>>& secondList) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,70 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 1851. Minimum Interval to Include Each Query :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*1851. Minimum Interval to Include Each Query][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*1851. Minimum Interval to Include Each Query][1851. Minimum Interval to Include Each Query]]
|
||||
:END:
|
||||
|
||||
You are given a 2D integer array ~intervals~, where ~intervals[i] = [left_{i}, right_{i}]~ describes the ~i^{th}~ interval starting at ~left_{i}~ and ending at ~right_{i}~ *(inclusive)*. The *size* of an interval is defined as the number of integers it contains, or more formally ~right_{i} - left_{i} + 1~.
|
||||
|
||||
You are also given an integer array ~queries~. The answer to the ~j^{th}~ query is the *size of the smallest interval* ~i~ such that ~left_{i} <= queries[j] <= right_{i}~. If no such interval exists, the answer is ~-1~.
|
||||
|
||||
Return /an array containing the answers to the queries/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]
|
||||
Output: [3,3,1,4]
|
||||
Explanation: The queries are processed as follows:
|
||||
- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.
|
||||
- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.
|
||||
- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.
|
||||
- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]
|
||||
Output: [2,-1,4,6]
|
||||
Explanation: The queries are processed as follows:
|
||||
- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.
|
||||
- Query = 19: None of the intervals contain 19. The answer is -1.
|
||||
- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.
|
||||
- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= intervals.length <= 10^{5}~
|
||||
|
||||
- ~1 <= queries.length <= 10^{5}~
|
||||
|
||||
- ~intervals[i].length == 2~
|
||||
|
||||
- ~1 <= left_{i} <= right_{i} <= 10^{7}~
|
||||
|
||||
- ~1 <= queries[j] <= 10^{7}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> minInterval(vector<vector<int>>& intervals, vector<int>& queries) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user