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:
+48
-3
@@ -1,18 +1,63 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0003. Longest Substring Without Repeating Characters :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0003. Longest Substring Without Repeating Characters][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0003. Longest Substring Without Repeating Characters][0003. Longest Substring Without Repeating Characters]]
|
||||
:END:
|
||||
|
||||
Given a string ~s~, find the length of the *longest* *substring* without duplicate characters.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "abcabcbb"
|
||||
Output: 3
|
||||
Explanation: The answer is "abc", with the length of 3. Note that "bca" and "cab" are also correct answers.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "bbbbb"
|
||||
Output: 1
|
||||
Explanation: The answer is "b", with the length of 1.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "pwwkew"
|
||||
Output: 3
|
||||
Explanation: The answer is "wke", with the length of 3.
|
||||
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~0 <= s.length <= 5 * 10^{4}~
|
||||
|
||||
- ~s~ consists of English letters, digits, symbols and spaces.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def lengthOfLongestSubstring(self, s: str) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int lengthOfLongestSubstring(string s) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,71 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0076. Minimum Window Substring :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0076. Minimum Window Substring][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0076. Minimum Window Substring][0076. Minimum Window Substring]]
|
||||
:END:
|
||||
|
||||
Given two strings ~s~ and ~t~ of lengths ~m~ and ~n~ respectively, return /the *minimum window*/ */substring/*/ of /~s~/ such that every character in /~t~/ (*including duplicates*) is included in the window/. If there is no such substring, return /the empty string /~""~.
|
||||
|
||||
The testcases will be generated such that the answer is *unique*.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "ADOBECODEBANC", t = "ABC"
|
||||
Output: "BANC"
|
||||
Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "a", t = "a"
|
||||
Output: "a"
|
||||
Explanation: The entire string s is the minimum window.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "a", t = "aa"
|
||||
Output: ""
|
||||
Explanation: Both 'a's from t must be included in the window.
|
||||
Since the largest window of s only has one 'a', return empty string.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~m == s.length~
|
||||
|
||||
- ~n == t.length~
|
||||
|
||||
- ~1 <= m, n <= 10^{5}~
|
||||
|
||||
- ~s~ and ~t~ consist of uppercase and lowercase English letters.
|
||||
|
||||
*Follow up:* Could you find an algorithm that runs in ~O(m + n)~ time?
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def minWindow(self, s: str, t: str) -> str:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
string minWindow(string s, string t) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,57 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0121. Best Time to Buy And Sell Stock :easy:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0121. Best Time to Buy And Sell Stock][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0121. Best Time to Buy And Sell Stock][0121. Best Time to Buy And Sell Stock]]
|
||||
:END:
|
||||
|
||||
You are given an array ~prices~ where ~prices[i]~ is the price of a given stock on the ~i^{th}~ day.
|
||||
|
||||
You want to maximize your profit by choosing a *single day* to buy one stock and choosing a *different day in the future* to sell that stock.
|
||||
|
||||
Return /the maximum profit you can achieve from this transaction/. If you cannot achieve any profit, return ~0~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: prices = [7,1,5,3,6,4]
|
||||
Output: 5
|
||||
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
|
||||
Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: prices = [7,6,4,3,1]
|
||||
Output: 0
|
||||
Explanation: In this case, no transactions are done and the max profit = 0.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= prices.length <= 10^{5}~
|
||||
|
||||
- ~0 <= prices[i] <= 10^{4}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxProfit(self, prices: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int maxProfit(vector<int>& prices) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,63 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0239. Sliding Window Maximum :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0239. Sliding Window Maximum][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0239. Sliding Window Maximum][0239. Sliding Window Maximum]]
|
||||
:END:
|
||||
|
||||
You are given an array of integers ~nums~, there is a sliding window of size ~k~ which is moving from the very left of the array to the very right. You can only see the ~k~ numbers in the window. Each time the sliding window moves right by one position.
|
||||
|
||||
Return /the max sliding window/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
|
||||
Output: [3,3,5,5,6,7]
|
||||
Explanation:
|
||||
Window position Max
|
||||
--------------- -----
|
||||
[1 3 -1] -3 5 3 6 7 3
|
||||
1 [3 -1 -3] 5 3 6 7 3
|
||||
1 3 [-1 -3 5] 3 6 7 5
|
||||
1 3 -1 [-3 5 3] 6 7 5
|
||||
1 3 -1 -3 [5 3 6] 7 6
|
||||
1 3 -1 -3 5 [3 6 7] 7
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1], k = 1
|
||||
Output: [1]
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 10^{5}~
|
||||
|
||||
- ~-10^{4} <= nums[i] <= 10^{4}~
|
||||
|
||||
- ~1 <= k <= nums.length~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
+43
-3
@@ -1,18 +1,58 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0424. Longest Repeating Character Replacement :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0424. Longest Repeating Character Replacement][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0424. Longest Repeating Character Replacement][0424. Longest Repeating Character Replacement]]
|
||||
:END:
|
||||
|
||||
You are given a string ~s~ and an integer ~k~. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most ~k~ times.
|
||||
|
||||
Return /the length of the longest substring containing the same letter you can get after performing the above operations/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "ABAB", k = 2
|
||||
Output: 4
|
||||
Explanation: Replace the two 'A's with two 'B's or vice versa.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "AABABBA", k = 1
|
||||
Output: 4
|
||||
Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".
|
||||
The substring "BBBB" has the longest repeating letters, which is 4.
|
||||
There may exists other ways to achieve this answer too.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 10^{5}~
|
||||
|
||||
- ~s~ consists of only uppercase English letters.
|
||||
|
||||
- ~0 <= k <= s.length~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def characterReplacement(self, s: str, k: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int characterReplacement(string s, int k) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0567. Permutation In String :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0567. Permutation In String][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0567. Permutation In String][0567. Permutation In String]]
|
||||
:END:
|
||||
|
||||
Given two strings ~s1~ and ~s2~, return ~true~ if ~s2~ contains a permutation of ~s1~, or ~false~ otherwise.
|
||||
|
||||
In other words, return ~true~ if one of ~s1~'s permutations is the substring of ~s2~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s1 = "ab", s2 = "eidbaooo"
|
||||
Output: true
|
||||
Explanation: s2 contains one permutation of s1 ("ba").
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s1 = "ab", s2 = "eidboaoo"
|
||||
Output: false
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s1.length, s2.length <= 10^{4}~
|
||||
|
||||
- ~s1~ and ~s2~ consist of lowercase English letters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def checkInclusion(self, s1: str, s2: str) -> bool:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool checkInclusion(string s1, string s2) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
+57
-3
@@ -1,18 +1,72 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 3306. Count of Substrings Containing Every Vowel and K Consonants II :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*3306. Count of Substrings Containing Every Vowel and K Consonants II][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*3306. Count of Substrings Containing Every Vowel and K Consonants II][3306. Count of Substrings Containing Every Vowel and K Consonants II]]
|
||||
:END:
|
||||
|
||||
You are given a string ~word~ and a *non-negative* integer ~k~.
|
||||
|
||||
Return the total number of substrings of ~word~ that contain every vowel (~'a'~, ~'e'~, ~'i'~, ~'o'~, and ~'u'~) *at least* once and *exactly* ~k~ consonants.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
*Input:* word = "aeioqq", k = 1
|
||||
|
||||
*Output:* 0
|
||||
|
||||
*Explanation:*
|
||||
|
||||
There is no substring with every vowel.
|
||||
|
||||
*Example 2:*
|
||||
|
||||
*Input:* word = "aeiou", k = 0
|
||||
|
||||
*Output:* 1
|
||||
|
||||
*Explanation:*
|
||||
|
||||
The only substring with every vowel and zero consonants is ~word[0..4]~, which is ~"aeiou"~.
|
||||
|
||||
*Example 3:*
|
||||
|
||||
*Input:* word = "ieaouqqieaouqq", k = 1
|
||||
|
||||
*Output:* 3
|
||||
|
||||
*Explanation:*
|
||||
|
||||
The substrings with every vowel and one consonant are:
|
||||
|
||||
- ~word[0..5]~, which is ~"ieaouq"~.
|
||||
|
||||
- ~word[6..11]~, which is ~"qieaou"~.
|
||||
|
||||
- ~word[7..12]~, which is ~"ieaouq"~.
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~5 <= word.length <= 2 * 10^{5}~
|
||||
|
||||
- ~word~ consists only of lowercase English letters.
|
||||
|
||||
- ~0 <= k <= word.length - 5~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def countOfSubstrings(self, word: str, k: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
long long countOfSubstrings(string word, int k) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user