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,102 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 2013. Detect Squares :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*2013. Detect Squares][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*2013. Detect Squares][2013. Detect Squares]]
|
||||
:END:
|
||||
|
||||
You are given a stream of points on the X-Y plane. Design an algorithm that:
|
||||
|
||||
- *Adds* new points from the stream into a data structure. *Duplicate* points are allowed and should be treated as different points.
|
||||
|
||||
- Given a query point, *counts* the number of ways to choose three points from the data structure such that the three points and the query point form an *axis-aligned square* with *positive area*.
|
||||
|
||||
An *axis-aligned square* is a square whose edges are all the same length and are either parallel or perpendicular to the x-axis and y-axis.
|
||||
|
||||
Implement the ~DetectSquares~ class:
|
||||
|
||||
- ~DetectSquares()~ Initializes the object with an empty data structure.
|
||||
|
||||
- ~void add(int[] point)~ Adds a new point ~point = [x, y]~ to the data structure.
|
||||
|
||||
- ~int count(int[] point)~ Counts the number of ways to form *axis-aligned squares* with point ~point = [x, y]~ as described above.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input
|
||||
["DetectSquares", "add", "add", "add", "count", "count", "add", "count"]
|
||||
[[], [[3, 10]], [[11, 2]], [[3, 2]], [[11, 10]], [[14, 8]], [[11, 2]], [[11, 10]]]
|
||||
Output
|
||||
[null, null, null, null, 1, 0, null, 2]
|
||||
|
||||
Explanation
|
||||
DetectSquares detectSquares = new DetectSquares();
|
||||
detectSquares.add([3, 10]);
|
||||
detectSquares.add([11, 2]);
|
||||
detectSquares.add([3, 2]);
|
||||
detectSquares.count([11, 10]); // return 1. You can choose:
|
||||
// - The first, second, and third points
|
||||
detectSquares.count([14, 8]); // return 0. The query point cannot form a square with any points in the data structure.
|
||||
detectSquares.add([11, 2]); // Adding duplicate points is allowed.
|
||||
detectSquares.count([11, 10]); // return 2. You can choose:
|
||||
// - The first, second, and third points
|
||||
// - The first, third, and fourth points
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~point.length == 2~
|
||||
|
||||
- ~0 <= x, y <= 1000~
|
||||
|
||||
- At most ~3000~ calls *in total* will be made to ~add~ and ~count~.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
class DetectSquares:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
def add(self, point: List[int]) -> None:
|
||||
|
||||
|
||||
def count(self, point: List[int]) -> int:
|
||||
|
||||
|
||||
|
||||
# Your DetectSquares object will be instantiated and called as such:
|
||||
# obj = DetectSquares()
|
||||
# obj.add(point)
|
||||
# param_2 = obj.count(point)
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
class DetectSquares {
|
||||
public:
|
||||
DetectSquares() {
|
||||
|
||||
}
|
||||
|
||||
void add(vector<int> point) {
|
||||
|
||||
}
|
||||
|
||||
int count(vector<int> point) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Your DetectSquares object will be instantiated and called as such:
|
||||
* DetectSquares* obj = new DetectSquares();
|
||||
* obj->add(point);
|
||||
* int param_2 = obj->count(point);
|
||||
*/
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user