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,103 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0208. Implement Trie Prefix Tree :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0208. Implement Trie Prefix Tree][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0208. Implement Trie Prefix Tree][0208. Implement Trie Prefix Tree]]
|
||||
:END:
|
||||
|
||||
A *trie* (pronounced as "try") or *prefix tree* is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.
|
||||
|
||||
Implement the Trie class:
|
||||
|
||||
- ~Trie()~ Initializes the trie object.
|
||||
|
||||
- ~void insert(String word)~ Inserts the string ~word~ into the trie.
|
||||
|
||||
- ~boolean search(String word)~ Returns ~true~ if the string ~word~ is in the trie (i.e., was inserted before), and ~false~ otherwise.
|
||||
|
||||
- ~boolean startsWith(String prefix)~ Returns ~true~ if there is a previously inserted string ~word~ that has the prefix ~prefix~, and ~false~ otherwise.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input
|
||||
["Trie", "insert", "search", "search", "startsWith", "insert", "search"]
|
||||
[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
|
||||
Output
|
||||
[null, null, true, false, true, null, true]
|
||||
|
||||
Explanation
|
||||
Trie trie = new Trie();
|
||||
trie.insert("apple");
|
||||
trie.search("apple"); // return True
|
||||
trie.search("app"); // return False
|
||||
trie.startsWith("app"); // return True
|
||||
trie.insert("app");
|
||||
trie.search("app"); // return True
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= word.length, prefix.length <= 2000~
|
||||
|
||||
- ~word~ and ~prefix~ consist only of lowercase English letters.
|
||||
|
||||
- At most ~3 * 10^{4}~ calls *in total* will be made to ~insert~, ~search~, and ~startsWith~.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
class Trie:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
def insert(self, word: str) -> None:
|
||||
|
||||
|
||||
def search(self, word: str) -> bool:
|
||||
|
||||
|
||||
def startsWith(self, prefix: str) -> bool:
|
||||
|
||||
|
||||
|
||||
# Your Trie object will be instantiated and called as such:
|
||||
# obj = Trie()
|
||||
# obj.insert(word)
|
||||
# param_2 = obj.search(word)
|
||||
# param_3 = obj.startsWith(prefix)
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
class Trie {
|
||||
public:
|
||||
Trie() {
|
||||
|
||||
}
|
||||
|
||||
void insert(string word) {
|
||||
|
||||
}
|
||||
|
||||
bool search(string word) {
|
||||
|
||||
}
|
||||
|
||||
bool startsWith(string prefix) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Your Trie object will be instantiated and called as such:
|
||||
* Trie* obj = new Trie();
|
||||
* obj->insert(word);
|
||||
* bool param_2 = obj->search(word);
|
||||
* bool param_3 = obj->startsWith(prefix);
|
||||
*/
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,97 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0211. Design Add And Search Words Data Structure :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0211. Design Add And Search Words Data Structure][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0211. Design Add And Search Words Data Structure][0211. Design Add And Search Words Data Structure]]
|
||||
:END:
|
||||
|
||||
Design a data structure that supports adding new words and finding if a string matches any previously added string.
|
||||
|
||||
Implement the ~WordDictionary~ class:
|
||||
|
||||
- ~WordDictionary()~ Initializes the object.
|
||||
|
||||
- ~void addWord(word)~ Adds ~word~ to the data structure, it can be matched later.
|
||||
|
||||
- ~bool search(word)~ Returns ~true~ if there is any string in the data structure that matches ~word~ or ~false~ otherwise. ~word~ may contain dots ~'.'~ where dots can be matched with any letter.
|
||||
|
||||
*Example:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input
|
||||
["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
|
||||
[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
|
||||
Output
|
||||
[null,null,null,null,false,true,true,true]
|
||||
|
||||
Explanation
|
||||
WordDictionary wordDictionary = new WordDictionary();
|
||||
wordDictionary.addWord("bad");
|
||||
wordDictionary.addWord("dad");
|
||||
wordDictionary.addWord("mad");
|
||||
wordDictionary.search("pad"); // return False
|
||||
wordDictionary.search("bad"); // return True
|
||||
wordDictionary.search(".ad"); // return True
|
||||
wordDictionary.search("b.."); // return True
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= word.length <= 25~
|
||||
|
||||
- ~word~ in ~addWord~ consists of lowercase English letters.
|
||||
|
||||
- ~word~ in ~search~ consist of ~'.'~ or lowercase English letters.
|
||||
|
||||
- There will be at most ~2~ dots in ~word~ for ~search~ queries.
|
||||
|
||||
- At most ~10^{4}~ calls will be made to ~addWord~ and ~search~.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
class WordDictionary:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
def addWord(self, word: str) -> None:
|
||||
|
||||
|
||||
def search(self, word: str) -> bool:
|
||||
|
||||
|
||||
|
||||
# Your WordDictionary object will be instantiated and called as such:
|
||||
# obj = WordDictionary()
|
||||
# obj.addWord(word)
|
||||
# param_2 = obj.search(word)
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
class WordDictionary {
|
||||
public:
|
||||
WordDictionary() {
|
||||
|
||||
}
|
||||
|
||||
void addWord(string word) {
|
||||
|
||||
}
|
||||
|
||||
bool search(string word) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Your WordDictionary object will be instantiated and called as such:
|
||||
* WordDictionary* obj = new WordDictionary();
|
||||
* obj->addWord(word);
|
||||
* bool param_2 = obj->search(word);
|
||||
*/
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,64 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0212. Word Search II :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0212. Word Search II][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0212. Word Search II][0212. Word Search II]]
|
||||
:END:
|
||||
|
||||
Given an ~m x n~ ~board~ of characters and a list of strings ~words~, return /all words on the board/.
|
||||
|
||||
Each word must be constructed from letters of sequentially adjacent cells, where *adjacent cells* are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
|
||||
Output: ["eat","oath"]
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: board = [["a","b"],["c","d"]], words = ["abcb"]
|
||||
Output: []
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~m == board.length~
|
||||
|
||||
- ~n == board[i].length~
|
||||
|
||||
- ~1 <= m, n <= 12~
|
||||
|
||||
- ~board[i][j]~ is a lowercase English letter.
|
||||
|
||||
- ~1 <= words.length <= 3 * 10^{4}~
|
||||
|
||||
- ~1 <= words[i].length <= 10~
|
||||
|
||||
- ~words[i]~ consists of lowercase English letters.
|
||||
|
||||
- All the strings of ~words~ are unique.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def findWords(self, board: List[List[str]], words: List[str]) -> List[str]:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<string> findWords(vector<vector<char>>& board, vector<string>& words) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 1166. Design File System :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*1166. Design File System][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*1166. Design File System][1166. Design File System]]
|
||||
:END:
|
||||
|
||||
** TODO Approach
|
||||
|
||||
Reference in New Issue
Block a user