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,59 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0011. Container With Most Water :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0011. Container With Most Water][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0011. Container With Most Water][0011. Container With Most Water]]
|
||||
:END:
|
||||
|
||||
You are given an integer array ~height~ of length ~n~. There are ~n~ vertical lines drawn such that the two endpoints of the ~i^{th}~ line are ~(i, 0)~ and ~(i, height[i])~.
|
||||
|
||||
Find two lines that together with the x-axis form a container, such that the container contains the most water.
|
||||
|
||||
Return /the maximum amount of water a container can store/.
|
||||
|
||||
*Notice* that you may not slant the container.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: height = [1,8,6,2,5,4,8,3,7]
|
||||
Output: 49
|
||||
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: height = [1,1]
|
||||
Output: 1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~n == height.length~
|
||||
|
||||
- ~2 <= n <= 10^{5}~
|
||||
|
||||
- ~0 <= height[i] <= 10^{4}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxArea(self, height: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int maxArea(vector<int>& height) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,69 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0015. 3Sum :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0015. 3Sum][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0015. 3Sum][0015. 3Sum]]
|
||||
:END:
|
||||
|
||||
Given an integer array nums, return all the triplets ~[nums[i], nums[j], nums[k]]~ such that ~i != j~, ~i != k~, and ~j != k~, and ~nums[i] + nums[j] + nums[k] == 0~.
|
||||
|
||||
Notice that the solution set must not contain duplicate triplets.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [-1,0,1,2,-1,-4]
|
||||
Output: [[-1,-1,2],[-1,0,1]]
|
||||
Explanation:
|
||||
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
|
||||
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
|
||||
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
|
||||
The distinct triplets are [-1,0,1] and [-1,-1,2].
|
||||
Notice that the order of the output and the order of the triplets does not matter.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [0,1,1]
|
||||
Output: []
|
||||
Explanation: The only possible triplet does not sum up to 0.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [0,0,0]
|
||||
Output: [[0,0,0]]
|
||||
Explanation: The only possible triplet sums up to 0.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~3 <= nums.length <= 3000~
|
||||
|
||||
- ~-10^{5} <= nums[i] <= 10^{5}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def threeSum(self, nums: list[int]) -> list[list[int]]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<vector<int>> threeSum(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0042. Trapping Rain Water :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0042. Trapping Rain Water][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0042. Trapping Rain Water][0042. Trapping Rain Water]]
|
||||
:END:
|
||||
|
||||
Given ~n~ non-negative integers representing an elevation map where the width of each bar is ~1~, compute how much water it can trap after raining.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
|
||||
Output: 6
|
||||
Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: height = [4,2,0,3,2,5]
|
||||
Output: 9
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~n == height.length~
|
||||
|
||||
- ~1 <= n <= 2 * 10^{4}~
|
||||
|
||||
- ~0 <= height[i] <= 10^{5}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def trap(self, height: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int trap(vector<int>& height) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,65 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0125. Valid Palindrome :easy:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0125. Valid Palindrome][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0125. Valid Palindrome][0125. Valid Palindrome]]
|
||||
:END:
|
||||
|
||||
A phrase is a *palindrome* if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
|
||||
|
||||
Given a string ~s~, return ~true~/ if it is a *palindrome*, or /~false~/ otherwise/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "A man, a plan, a canal: Panama"
|
||||
Output: true
|
||||
Explanation: "amanaplanacanalpanama" is a palindrome.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "race a car"
|
||||
Output: false
|
||||
Explanation: "raceacar" is not a palindrome.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = " "
|
||||
Output: true
|
||||
Explanation: s is an empty string "" after removing non-alphanumeric characters.
|
||||
Since an empty string reads the same forward and backward, it is a palindrome.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 2 * 10^{5}~
|
||||
|
||||
- ~s~ consists only of printable ASCII characters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def isPalindrome(self, s: str) -> bool:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool isPalindrome(string s) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,74 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0167. Two Sum II Input Array Is Sorted :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0167. Two Sum II Input Array Is Sorted][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0167. Two Sum II Input Array Is Sorted][0167. Two Sum II Input Array Is Sorted]]
|
||||
:END:
|
||||
|
||||
Given a *1-indexed* array of integers ~numbers~ that is already */sorted in non-decreasing order/*, find two numbers such that they add up to a specific ~target~ number. Let these two numbers be ~numbers[index_{1}]~ and ~numbers[index_{2}]~ where ~1 <= index_{1} < index_{2} <= numbers.length~.
|
||||
|
||||
Return/ the indices of the two numbers /~index_{1}~/ and /~index_{2}~/, *each incremented by one,* as an integer array /~[index_{1}, index_{2}]~/ of length 2./
|
||||
|
||||
The tests are generated such that there is *exactly one solution*. You *may not* use the same element twice.
|
||||
|
||||
Your solution must use only constant extra space.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: numbers = [2,7,11,15], target = 9
|
||||
Output: [1,2]
|
||||
Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: numbers = [2,3,4], target = 6
|
||||
Output: [1,3]
|
||||
Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: numbers = [-1,0], target = -1
|
||||
Output: [1,2]
|
||||
Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~2 <= numbers.length <= 3 * 10^{4}~
|
||||
|
||||
- ~-1000 <= numbers[i] <= 1000~
|
||||
|
||||
- ~numbers~ is sorted in *non-decreasing order*.
|
||||
|
||||
- ~-1000 <= target <= 1000~
|
||||
|
||||
- The tests are generated such that there is *exactly one solution*.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def twoSum(self, numbers: List[int], target: int) -> List[int]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> twoSum(vector<int>& numbers, int target) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0259. 3Sum Smaller :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0259. 3Sum Smaller][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0259. 3Sum Smaller][0259. 3Sum Smaller]]
|
||||
:END:
|
||||
|
||||
** TODO Approach
|
||||
|
||||
@@ -1,18 +1,53 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0344. Reverse String :easy:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0344. Reverse String][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0344. Reverse String][0344. Reverse String]]
|
||||
:END:
|
||||
|
||||
Write a function that reverses a string. The input string is given as an array of characters ~s~.
|
||||
|
||||
You must do this by modifying the input array in-place with ~O(1)~ extra memory.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = ["h","e","l","l","o"]
|
||||
Output: ["o","l","l","e","h"]
|
||||
#+end_src
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = ["H","a","n","n","a","h"]
|
||||
Output: ["h","a","n","n","a","H"]
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 10^{5}~
|
||||
|
||||
- ~s[i]~ is a printable ascii character.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def reverseString(self, s: List[str]) -> None:
|
||||
"""
|
||||
Do not return anything, modify s in-place instead.
|
||||
"""
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
void reverseString(vector<char>& s) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user