diff --git a/Makefile b/Makefile index 960de8bb..d0b957be 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ search: clean: find . -name ".DS_Store" -type f -delete -# delete __pycache__ folders find . -name "__pycache__" -type d -exec rm -r {} + + find . -name "output" -type d -exec rm -r {} + push: git add . @@ -18,11 +18,5 @@ push: sync: poetry run python utils/sync.py -pre-commit: - poetry run pre-commit run --all-files - -generate: - poetry run python utils/sync.py - poetry run python utils/integrate.py - poetry run pre-commit run --all-files - poetry run pre-commit run --all-files +format: + poetry run pre-commit run --all-files || $(MAKE) format diff --git a/docs/blind75/advanced_graphs.md b/docs/blind75/advanced_graphs.md index 47d8ac88..90dd24ec 100644 --- a/docs/blind75/advanced_graphs.md +++ b/docs/blind75/advanced_graphs.md @@ -6,6 +6,8 @@ comments: True ## 269. Alien Dictionary +- Return the correct order of characters in the alien language. + === "Python" ```python diff --git a/docs/blind75/graphs.md b/docs/blind75/graphs.md index 156a12a2..d5445d4d 100644 --- a/docs/blind75/graphs.md +++ b/docs/blind75/graphs.md @@ -85,6 +85,19 @@ comments: True - Return true if it is possible to finish all courses, otherwise return false. - Dependency relationships imply the topological sort algorithm. - Cycle detection +- Topological Sort + - DAG (Directed Acyclic Graph) + - Time complexity: O(V+E) + - Space complexity: O(V+E) + - Prerequisites: Indegree (Look at the problem [1557. Minimum Number of Vertices to Reach All Nodes](#1557-minimum-number-of-vertices-to-reach-all-nodes)) + - Indegree: Number of incoming edges to a vertex + - Applications: task scheduling, course scheduling, build systems, dependency resolution, compiler optimization, etc. + +![ts1](../assets/graph_ts1.png){width=300px} + +![ts2](../assets/graph_ts2.png){width=300px} + +Course to prerequisites mapping ```mermaid flowchart LR @@ -95,6 +108,7 @@ flowchart LR 1((1)) --> 4((4)) ``` +Prerequisites to course mapping ```mermaid flowchart LR @@ -128,8 +142,7 @@ Initialize | in-degree | 2 | 2 | 0 | 1 | 0 | - queue: `[2, 4]` - -Pop `2` from the queue +- pop `2` from the queue ```mermaid flowchart LR @@ -144,8 +157,7 @@ flowchart LR | in-degree | 1 | 2 | 0 | 1 | 0 | - queue: `[4]` - -Pop `4` from the queue +- pop `4` from the queue ```mermaid flowchart LR @@ -158,8 +170,7 @@ flowchart LR | in-degree | 1 | 1 | 0 | 0 | 0 | - queue: `[3]` - -Pop `3` from the queue +- pop `3` from the queue ```mermaid flowchart LR @@ -171,8 +182,7 @@ flowchart LR | in-degree | 1 | 0 | 0 | 0 | 0 | - queue: `[1]` - -Pop `1` from the queue +- pop `1` from the queue ```mermaid flowchart LR @@ -184,8 +194,8 @@ flowchart LR | in-degree | 0 | 0 | 0 | 0 | 0 | - queue: `[0]` - -Pop `0` from the queue +- pop `0` from the queue +- All courses are taken. Return `True`. === "Python" diff --git a/docs/blind75/stack.md b/docs/blind75/stack.md index 0c26fcf0..15e941e1 100644 --- a/docs/blind75/stack.md +++ b/docs/blind75/stack.md @@ -6,6 +6,18 @@ comments: True ## 20. Valid Parentheses +- Determine if the input string is valid. +- Steps for the string `()[]{}`: + +| char | action | stack | +| ---- | ------ | ----- | +| `(` | push | "\(" | +| `)` | pop | "" | +| `[` | push | "\[" | +| `]` | pop | "" | +| `{` | push | "\{" | +| `}` | pop | "" | + === "Python" ```python diff --git a/docs/blind75/tries.md b/docs/blind75/tries.md index e1f5c4ff..e4e5f767 100644 --- a/docs/blind75/tries.md +++ b/docs/blind75/tries.md @@ -6,6 +6,25 @@ comments: True ## 208. Implement Trie (Prefix Tree) +## Trie + +- A trie is a tree-like data structure whose nodes store the letters of an alphabet. + +```mermaid +flowchart TD +Root(( )) +Root --- C1(("C")) +Root --- D((D)) +C1 --- A1(("A")) +A1 --- T1(("T")) +A1 --- R1(("R")) +A1 --- N((N)) +Root --- B1((B)) +B1 --- A2((A)) +A2 --- T2((T)) +A2 --- R2((R)) +``` + === "Python" ```python diff --git a/docs/graph_theory/mst.md b/docs/graph_theory/mst.md index d129db5b..09570ea4 100644 --- a/docs/graph_theory/mst.md +++ b/docs/graph_theory/mst.md @@ -69,6 +69,10 @@ MST ## 1168. Optimize Water Distribution in a Village +![1168_0](../assets/1168_0.png) + +![1168_1](../assets/1168_1.png) + === "Python" ```python diff --git a/docs/graph_theory/standard_traversal.md b/docs/graph_theory/standard_traversal.md index cd414b99..ce7dd0c6 100644 --- a/docs/graph_theory/standard_traversal.md +++ b/docs/graph_theory/standard_traversal.md @@ -6,6 +6,19 @@ comments: True ## 547. Number of Provinces +- Return the number of provinces. + +### Union Find + +- Find by Path Compression +- Union by Rank +- Time Complexity: O(log(n)) +- Space Complexity: O(n) + +```python title="template/union_find.py" +--8<-- "template/union_find.py" +``` + === "Python" ```python diff --git a/docs/graph_theory/topological_sort.md b/docs/graph_theory/topological_sort.md index 6f7bc26c..8a2d9100 100644 --- a/docs/graph_theory/topological_sort.md +++ b/docs/graph_theory/topological_sort.md @@ -9,6 +9,19 @@ comments: True - Return true if it is possible to finish all courses, otherwise return false. - Dependency relationships imply the topological sort algorithm. - Cycle detection +- Topological Sort + - DAG (Directed Acyclic Graph) + - Time complexity: O(V+E) + - Space complexity: O(V+E) + - Prerequisites: Indegree (Look at the problem [1557. Minimum Number of Vertices to Reach All Nodes](#1557-minimum-number-of-vertices-to-reach-all-nodes)) + - Indegree: Number of incoming edges to a vertex + - Applications: task scheduling, course scheduling, build systems, dependency resolution, compiler optimization, etc. + +![ts1](../assets/graph_ts1.png){width=300px} + +![ts2](../assets/graph_ts2.png){width=300px} + +Course to prerequisites mapping ```mermaid flowchart LR @@ -19,6 +32,7 @@ flowchart LR 1((1)) --> 4((4)) ``` +Prerequisites to course mapping ```mermaid flowchart LR @@ -52,8 +66,7 @@ Initialize | in-degree | 2 | 2 | 0 | 1 | 0 | - queue: `[2, 4]` - -Pop `2` from the queue +- pop `2` from the queue ```mermaid flowchart LR @@ -68,8 +81,7 @@ flowchart LR | in-degree | 1 | 2 | 0 | 1 | 0 | - queue: `[4]` - -Pop `4` from the queue +- pop `4` from the queue ```mermaid flowchart LR @@ -82,8 +94,7 @@ flowchart LR | in-degree | 1 | 1 | 0 | 0 | 0 | - queue: `[3]` - -Pop `3` from the queue +- pop `3` from the queue ```mermaid flowchart LR @@ -95,8 +106,7 @@ flowchart LR | in-degree | 1 | 0 | 0 | 0 | 0 | - queue: `[1]` - -Pop `1` from the queue +- pop `1` from the queue ```mermaid flowchart LR @@ -108,8 +118,8 @@ flowchart LR | in-degree | 0 | 0 | 0 | 0 | 0 | - queue: `[0]` - -Pop `0` from the queue +- pop `0` from the queue +- All courses are taken. Return `True`. === "Python" @@ -131,6 +141,10 @@ Pop `0` from the queue ## 210. Course Schedule II +- Return the ordering of courses you should take to finish all courses. If there are multiple valid answers, return any of them. + +![0207](../assets/0207.png){width=300px} + === "Python" ```python @@ -151,6 +165,8 @@ Pop `0` from the queue ## 269. Alien Dictionary +- Return the correct order of characters in the alien language. + === "Python" ```python @@ -171,6 +187,8 @@ Pop `0` from the queue ## 1203. Sort Items by Groups Respecting Dependencies +- Return any permutation of the items that satisfies the requirements. + === "Python" ```python diff --git a/docs/grind75/binary_tree.md b/docs/grind75/binary_tree.md index 4e457cfa..07f39012 100644 --- a/docs/grind75/binary_tree.md +++ b/docs/grind75/binary_tree.md @@ -126,6 +126,16 @@ comments: True ## 199. Binary Tree Right Side View +```plaintext + ____1 <--- + / \ + 2__ 2 <--- Look at the rightmost node at each level + / \ \ +3 4 3 <--- + / + 5 <--- +``` + === "Python" ```python diff --git a/docs/grind75/graph.md b/docs/grind75/graph.md index 91dec121..6e190d81 100644 --- a/docs/grind75/graph.md +++ b/docs/grind75/graph.md @@ -100,6 +100,19 @@ comments: True - Return true if it is possible to finish all courses, otherwise return false. - Dependency relationships imply the topological sort algorithm. - Cycle detection +- Topological Sort + - DAG (Directed Acyclic Graph) + - Time complexity: O(V+E) + - Space complexity: O(V+E) + - Prerequisites: Indegree (Look at the problem [1557. Minimum Number of Vertices to Reach All Nodes](#1557-minimum-number-of-vertices-to-reach-all-nodes)) + - Indegree: Number of incoming edges to a vertex + - Applications: task scheduling, course scheduling, build systems, dependency resolution, compiler optimization, etc. + +![ts1](../assets/graph_ts1.png){width=300px} + +![ts2](../assets/graph_ts2.png){width=300px} + +Course to prerequisites mapping ```mermaid flowchart LR @@ -110,6 +123,7 @@ flowchart LR 1((1)) --> 4((4)) ``` +Prerequisites to course mapping ```mermaid flowchart LR @@ -143,8 +157,7 @@ Initialize | in-degree | 2 | 2 | 0 | 1 | 0 | - queue: `[2, 4]` - -Pop `2` from the queue +- pop `2` from the queue ```mermaid flowchart LR @@ -159,8 +172,7 @@ flowchart LR | in-degree | 1 | 2 | 0 | 1 | 0 | - queue: `[4]` - -Pop `4` from the queue +- pop `4` from the queue ```mermaid flowchart LR @@ -173,8 +185,7 @@ flowchart LR | in-degree | 1 | 1 | 0 | 0 | 0 | - queue: `[3]` - -Pop `3` from the queue +- pop `3` from the queue ```mermaid flowchart LR @@ -186,8 +197,7 @@ flowchart LR | in-degree | 1 | 0 | 0 | 0 | 0 | - queue: `[1]` - -Pop `1` from the queue +- pop `1` from the queue ```mermaid flowchart LR @@ -199,8 +209,8 @@ flowchart LR | in-degree | 0 | 0 | 0 | 0 | 0 | - queue: `[0]` - -Pop `0` from the queue +- pop `0` from the queue +- All courses are taken. Return `True`. === "Python" diff --git a/docs/grind75/stack.md b/docs/grind75/stack.md index eb551700..e3722186 100644 --- a/docs/grind75/stack.md +++ b/docs/grind75/stack.md @@ -6,6 +6,18 @@ comments: True ## 20. Valid Parentheses +- Determine if the input string is valid. +- Steps for the string `()[]{}`: + +| char | action | stack | +| ---- | ------ | ----- | +| `(` | push | "\(" | +| `)` | pop | "" | +| `[` | push | "\[" | +| `]` | pop | "" | +| `{` | push | "\{" | +| `}` | pop | "" | + === "Python" ```python @@ -26,6 +38,12 @@ comments: True ## 232. Implement Queue using Stacks +- Implement the following operations of a queue using stacks. + - `push(x)` - Push element x to the back of queue. + - `pop()` - Removes the element from in front of queue. + - `peek()` - Get the front element. + - `empty()` - Return whether the queue is empty. + === "Python" ```python @@ -46,6 +64,16 @@ comments: True ## 150. Evaluate Reverse Polish Notation +- Steps for the list `["2", "1", "+", "3", "*"]`: + +| token | action | stack | +| ----- | ------ | -------- | +| `2` | push | `[2]` | +| `1` | push | `[2, 1]` | +| `+` | pop | `[3]` | +| `3` | push | `[3, 3]` | +| `*` | pop | `[9]` | + === "Python" ```python @@ -66,6 +94,8 @@ comments: True ## 155. Min Stack +- Implement a stack that supports push, pop, top, and retrieving the minimum element in constant time. + === "Python" ```python diff --git a/docs/grind75/trie.md b/docs/grind75/trie.md index b6af50fc..5d61dc0e 100644 --- a/docs/grind75/trie.md +++ b/docs/grind75/trie.md @@ -6,6 +6,25 @@ comments: True ## 208. Implement Trie (Prefix Tree) +## Trie + +- A trie is a tree-like data structure whose nodes store the letters of an alphabet. + +```mermaid +flowchart TD +Root(( )) +Root --- C1(("C")) +Root --- D((D)) +C1 --- A1(("A")) +A1 --- T1(("T")) +A1 --- R1(("R")) +A1 --- N((N)) +Root --- B1((B)) +B1 --- A2((A)) +A2 --- T2((T)) +A2 --- R2((R)) +``` + === "Python" ```python diff --git a/docs/leetpattern/bst.md b/docs/leetpattern/bst.md new file mode 100644 index 00000000..ed2f74f6 --- /dev/null +++ b/docs/leetpattern/bst.md @@ -0,0 +1,306 @@ +--- +comments: True +--- + +# BST + +## 700. Search in a Binary Search Tree + +### Binary Search Tree + +1. Binary Tree +2. Left subtree of a node contains only nodes with keys less than the node's key +3. Right subtree of a node contains only nodes with keys greater than the node's key +4. The left and right subtree each must also be a binary search tree +5. There must be no duplicate nodes +6. Inorder traversal of a BST gives a sorted list of keys + +```mermaid +graph TD +4((4)) --- 2((2)) +4 --- 7((7)) +2 --- 1((1)) +2 --- 3((3)) +``` + +=== "Python" + + ```python + --8<-- "0700_search_in_a_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0700_search_in_a_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0700_search_in_a_binary_search_tree.ts" + ``` + +## 98. Validate Binary Search Tree + +=== "Python" + + ```python + --8<-- "0098_validate_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0098_validate_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0098_validate_binary_search_tree.ts" + ``` + +## 530. Minimum Absolute Difference in BST + +=== "Python" + + ```python + --8<-- "0530_minimum_absolute_difference_in_bst.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0530_minimum_absolute_difference_in_bst.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0530_minimum_absolute_difference_in_bst.ts" + ``` + +## 501. Find Mode in Binary Search Tree + +=== "Python" + + ```python + --8<-- "0501_find_mode_in_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0501_find_mode_in_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0501_find_mode_in_binary_search_tree.ts" + ``` + +## 235. Lowest Common Ancestor of a Binary Search Tree + +=== "Python" + + ```python + --8<-- "0235_lowest_common_ancestor_of_a_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0235_lowest_common_ancestor_of_a_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0235_lowest_common_ancestor_of_a_binary_search_tree.ts" + ``` + +## 701. Insert into a Binary Search Tree + +=== "Python" + + ```python + --8<-- "0701_insert_into_a_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0701_insert_into_a_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0701_insert_into_a_binary_search_tree.ts" + ``` + +## 450. Delete Node in a BST + +=== "Python" + + ```python + --8<-- "0450_delete_node_in_a_bst.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0450_delete_node_in_a_bst.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0450_delete_node_in_a_bst.ts" + ``` + +## 669. Trim a Binary Search Tree + +=== "Python" + + ```python + --8<-- "0669_trim_a_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0669_trim_a_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0669_trim_a_binary_search_tree.ts" + ``` + +## 108. Convert Sorted Array to Binary Search Tree + +=== "Python" + + ```python + --8<-- "0108_convert_sorted_array_to_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0108_convert_sorted_array_to_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0108_convert_sorted_array_to_binary_search_tree.ts" + ``` + +## 109. Convert Sorted List to Binary Search Tree + +![109](https://assets.leetcode.com/uploads/2020/08/17/linked.jpg) + +=== "Python" + + ```python + --8<-- "0109_convert_sorted_list_to_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0109_convert_sorted_list_to_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0109_convert_sorted_list_to_binary_search_tree.ts" + ``` + +## 538. Convert BST to Greater Tree + +![538](https://assets.leetcode.com/uploads/2019/05/02/tree.png) + +=== "Python" + + ```python + --8<-- "0538_convert_bst_to_greater_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0538_convert_bst_to_greater_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0538_convert_bst_to_greater_tree.ts" + ``` + +## 230. Kth Smallest Element in a BST + +=== "Python" + + ```python + --8<-- "0230_kth_smallest_element_in_a_bst.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0230_kth_smallest_element_in_a_bst.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0230_kth_smallest_element_in_a_bst.ts" + ``` + +## 173. Binary Search Tree Iterator + +=== "Python" + + ```python + --8<-- "0173_binary_search_tree_iterator.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0173_binary_search_tree_iterator.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0173_binary_search_tree_iterator.ts" + ``` + +## 1586. Binary Search Tree Iterator II + +=== "Python" + + ```python + --8<-- "1586_binary_search_tree_iterator_ii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/1586_binary_search_tree_iterator_ii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/1586_binary_search_tree_iterator_ii.ts" + ``` diff --git a/docs/leetpattern/graph_bellman_ford.md b/docs/leetpattern/graph_bellman_ford.md index bab1054d..ca8f9ff1 100644 --- a/docs/leetpattern/graph_bellman_ford.md +++ b/docs/leetpattern/graph_bellman_ford.md @@ -6,6 +6,27 @@ comments: True ## 743. Network Delay Time +- Return the minimum time taken to reach all nodes in a network. + +```mermaid +graph LR +1((1)) +2((2)) +3((3)) +4((4)) +2 --> |1| 1 +2 --> |1| 3 +3 --> |1| 4 +``` + +- Shortest Path Problem: Find the shortest path between two vertices in a graph. +- Dijkstra's Algorithm + - Shortest path algorithm + - Weighted graph (non-negative weights) + - Data Structure: Heap; Hash Set + - Time Complexity: O(E \* logV) + - Space Complexity: O(V) + === "Python" ```python diff --git a/docs/leetpattern/graph_minimum_spanning_tree.md b/docs/leetpattern/graph_minimum_spanning_tree.md index 5ad5c24f..3442de08 100644 --- a/docs/leetpattern/graph_minimum_spanning_tree.md +++ b/docs/leetpattern/graph_minimum_spanning_tree.md @@ -69,6 +69,10 @@ MST ## 1168. Optimize Water Distribution in a Village +![1168_0](../assets/1168_0.png) + +![1168_1](../assets/1168_1.png) + === "Python" ```python @@ -109,6 +113,8 @@ MST ## 1631. Path With Minimum Effort +- Return the minimum effort required to travel from the top-left to the bottom-right corner. + === "Python" ```python diff --git a/docs/leetpattern/graph_shortest_path.md b/docs/leetpattern/graph_shortest_path.md index a55bb8f7..68836e33 100644 --- a/docs/leetpattern/graph_shortest_path.md +++ b/docs/leetpattern/graph_shortest_path.md @@ -6,6 +6,27 @@ comments: True ## 743. Network Delay Time +- Return the minimum time taken to reach all nodes in a network. + +```mermaid +graph LR +1((1)) +2((2)) +3((3)) +4((4)) +2 --> |1| 1 +2 --> |1| 3 +3 --> |1| 4 +``` + +- Shortest Path Problem: Find the shortest path between two vertices in a graph. +- Dijkstra's Algorithm + - Shortest path algorithm + - Weighted graph (non-negative weights) + - Data Structure: Heap; Hash Set + - Time Complexity: O(E \* logV) + - Space Complexity: O(V) + === "Python" ```python @@ -26,6 +47,10 @@ comments: True ## 778. Swim in Rising Water +- Return the minimum time when you can reach the target. + +![778](https://assets.leetcode.com/uploads/2021/06/29/swim2-grid-1.jpg) + === "Python" ```python @@ -46,6 +71,8 @@ comments: True ## 1631. Path With Minimum Effort +- Return the minimum effort required to travel from the top-left to the bottom-right corner. + === "Python" ```python @@ -203,6 +230,10 @@ graph TD ## 1168. Optimize Water Distribution in a Village +![1168_0](../assets/1168_0.png) + +![1168_1](../assets/1168_1.png) + === "Python" ```python diff --git a/docs/leetpattern/graph_topological_sort.md b/docs/leetpattern/graph_topological_sort.md index 95f7bcbb..06ae1c63 100644 --- a/docs/leetpattern/graph_topological_sort.md +++ b/docs/leetpattern/graph_topological_sort.md @@ -73,6 +73,19 @@ comments: True - Return true if it is possible to finish all courses, otherwise return false. - Dependency relationships imply the topological sort algorithm. - Cycle detection +- Topological Sort + - DAG (Directed Acyclic Graph) + - Time complexity: O(V+E) + - Space complexity: O(V+E) + - Prerequisites: Indegree (Look at the problem [1557. Minimum Number of Vertices to Reach All Nodes](#1557-minimum-number-of-vertices-to-reach-all-nodes)) + - Indegree: Number of incoming edges to a vertex + - Applications: task scheduling, course scheduling, build systems, dependency resolution, compiler optimization, etc. + +![ts1](../assets/graph_ts1.png){width=300px} + +![ts2](../assets/graph_ts2.png){width=300px} + +Course to prerequisites mapping ```mermaid flowchart LR @@ -83,6 +96,7 @@ flowchart LR 1((1)) --> 4((4)) ``` +Prerequisites to course mapping ```mermaid flowchart LR @@ -116,8 +130,7 @@ Initialize | in-degree | 2 | 2 | 0 | 1 | 0 | - queue: `[2, 4]` - -Pop `2` from the queue +- pop `2` from the queue ```mermaid flowchart LR @@ -132,8 +145,7 @@ flowchart LR | in-degree | 1 | 2 | 0 | 1 | 0 | - queue: `[4]` - -Pop `4` from the queue +- pop `4` from the queue ```mermaid flowchart LR @@ -146,8 +158,7 @@ flowchart LR | in-degree | 1 | 1 | 0 | 0 | 0 | - queue: `[3]` - -Pop `3` from the queue +- pop `3` from the queue ```mermaid flowchart LR @@ -159,8 +170,7 @@ flowchart LR | in-degree | 1 | 0 | 0 | 0 | 0 | - queue: `[1]` - -Pop `1` from the queue +- pop `1` from the queue ```mermaid flowchart LR @@ -172,8 +182,8 @@ flowchart LR | in-degree | 0 | 0 | 0 | 0 | 0 | - queue: `[0]` - -Pop `0` from the queue +- pop `0` from the queue +- All courses are taken. Return `True`. === "Python" @@ -195,6 +205,10 @@ Pop `0` from the queue ## 210. Course Schedule II +- Return the ordering of courses you should take to finish all courses. If there are multiple valid answers, return any of them. + +![0207](../assets/0207.png){width=300px} + === "Python" ```python @@ -215,6 +229,8 @@ Pop `0` from the queue ## 269. Alien Dictionary +- Return the correct order of characters in the alien language. + === "Python" ```python @@ -235,6 +251,8 @@ Pop `0` from the queue ## 1203. Sort Items by Groups Respecting Dependencies +- Return any permutation of the items that satisfies the requirements. + === "Python" ```python @@ -275,6 +293,10 @@ Pop `0` from the queue ## 1136. Parallel Courses +- Return the minimum number of semesters needed to take all courses. + +![1136](../assets/1136.png){width=300px} + === "Python" ```python diff --git a/docs/leetpattern/graph_union_find.md b/docs/leetpattern/graph_union_find.md index fa0306f6..42f1e6ff 100644 --- a/docs/leetpattern/graph_union_find.md +++ b/docs/leetpattern/graph_union_find.md @@ -6,6 +6,19 @@ comments: True ## 547. Number of Provinces +- Return the number of provinces. + +### Union Find + +- Find by Path Compression +- Union by Rank +- Time Complexity: O(log(n)) +- Space Complexity: O(n) + +```python title="template/union_find.py" +--8<-- "template/union_find.py" +``` + === "Python" ```python diff --git a/docs/leetpattern/queue.md b/docs/leetpattern/queue.md new file mode 100644 index 00000000..e396794b --- /dev/null +++ b/docs/leetpattern/queue.md @@ -0,0 +1,51 @@ +--- +comments: True +--- + +# Queue + +## 232. Implement Queue using Stacks + +- Implement the following operations of a queue using stacks. + - `push(x)` - Push element x to the back of queue. + - `pop()` - Removes the element from in front of queue. + - `peek()` - Get the front element. + - `empty()` - Return whether the queue is empty. + +=== "Python" + + ```python + --8<-- "0232_implement_queue_using_stacks.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0232_implement_queue_using_stacks.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0232_implement_queue_using_stacks.ts" + ``` + +## 225. Implement Stack using Queues + +=== "Python" + + ```python + --8<-- "0225_implement_stack_using_queues.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0225_implement_stack_using_queues.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0225_implement_stack_using_queues.ts" + ``` diff --git a/docs/leetpattern/queue_monotonic.md b/docs/leetpattern/queue_monotonic.md new file mode 100644 index 00000000..df5079a8 --- /dev/null +++ b/docs/leetpattern/queue_monotonic.md @@ -0,0 +1,85 @@ +--- +comments: True +--- + +# Queue Monotonic + +## 918. Maximum Sum Circular Subarray + +=== "Python" + + ```python + --8<-- "0918_maximum_sum_circular_subarray.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0918_maximum_sum_circular_subarray.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0918_maximum_sum_circular_subarray.ts" + ``` + +## 862. Shortest Subarray with Sum at Least K + +=== "Python" + + ```python + --8<-- "0862_shortest_subarray_with_sum_at_least_k.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0862_shortest_subarray_with_sum_at_least_k.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0862_shortest_subarray_with_sum_at_least_k.ts" + ``` + +## 239. Sliding Window Maximum + +=== "Python" + + ```python + --8<-- "0239_sliding_window_maximum.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0239_sliding_window_maximum.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0239_sliding_window_maximum.ts" + ``` + +## 2398. Maximum Number of Robots Within Budget + +=== "Python" + + ```python + --8<-- "2398_maximum_number_of_robots_within_budget.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/2398_maximum_number_of_robots_within_budget.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/2398_maximum_number_of_robots_within_budget.ts" + ``` diff --git a/docs/leetpattern/stack.md b/docs/leetpattern/stack.md new file mode 100644 index 00000000..17166c30 --- /dev/null +++ b/docs/leetpattern/stack.md @@ -0,0 +1,303 @@ +--- +comments: True +--- + +# Stack + +## 2390. Removing Stars From a String + +- Remove all `*` characters and their adjacent characters from the string. + +- Steps for the string `leet**cod*e`: + +| char | action | stack | +| ---- | ------ | ------- | +| l | push | "l" | +| e | push | "le" | +| e | push | "lee" | +| t | push | "leet" | +| \* | pop | "lee" | +| \* | pop | "le" | +| c | push | "lec" | +| o | push | "leco" | +| d | push | "lecod" | +| \* | pop | "leco" | +| e | push | "lecoe" | + +=== "Python" + + ```python + --8<-- "2390_removing_stars_from_a_string.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/2390_removing_stars_from_a_string.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/2390_removing_stars_from_a_string.ts" + ``` + +## 1544. Make The String Great + +- Remove all adjacent characters that are the same and have different cases. +- Steps for the string `leEeetcode`: + +| char | action | stack | +| ---- | ------ | ---------- | +| l | push | "l" | +| e | push | "le" | +| E | pop | "l" | +| e | push | "le" | +| e | push | "lee" | +| t | push | "leet" | +| c | push | "leetc" | +| o | push | "leetco" | +| d | push | "leetcod" | +| e | push | "leetcode" | + +=== "Python" + + ```python + --8<-- "1544_make_the_string_great.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/1544_make_the_string_great.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/1544_make_the_string_great.ts" + ``` + +## 20. Valid Parentheses + +- Determine if the input string is valid. +- Steps for the string `()[]{}`: + +| char | action | stack | +| ---- | ------ | ----- | +| `(` | push | "\(" | +| `)` | pop | "" | +| `[` | push | "\[" | +| `]` | pop | "" | +| `{` | push | "\{" | +| `}` | pop | "" | + +=== "Python" + + ```python + --8<-- "0020_valid_parentheses.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0020_valid_parentheses.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0020_valid_parentheses.ts" + ``` + +## 155. Min Stack + +- Implement a stack that supports push, pop, top, and retrieving the minimum element in constant time. + +=== "Python" + + ```python + --8<-- "0155_min_stack.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0155_min_stack.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0155_min_stack.ts" + ``` + +## 150. Evaluate Reverse Polish Notation + +- Steps for the list `["2", "1", "+", "3", "*"]`: + +| token | action | stack | +| ----- | ------ | -------- | +| `2` | push | `[2]` | +| `1` | push | `[2, 1]` | +| `+` | pop | `[3]` | +| `3` | push | `[3, 3]` | +| `*` | pop | `[9]` | + +=== "Python" + + ```python + --8<-- "0150_evaluate_reverse_polish_notation.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0150_evaluate_reverse_polish_notation.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0150_evaluate_reverse_polish_notation.ts" + ``` + +## 394. Decode String + +=== "Python" + + ```python + --8<-- "0394_decode_string.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0394_decode_string.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0394_decode_string.ts" + ``` + +## 22. Generate Parentheses + +=== "Python" + + ```python + --8<-- "0022_generate_parentheses.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0022_generate_parentheses.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0022_generate_parentheses.ts" + ``` + +## 853. Car Fleet + +=== "Python" + + ```python + --8<-- "0853_car_fleet.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0853_car_fleet.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0853_car_fleet.ts" + ``` + +## 224. Basic Calculator + +=== "Python" + + ```python + --8<-- "0224_basic_calculator.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0224_basic_calculator.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0224_basic_calculator.ts" + ``` + +## 227. Basic Calculator II + +=== "Python" + + ```python + --8<-- "0227_basic_calculator_ii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0227_basic_calculator_ii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0227_basic_calculator_ii.ts" + ``` + +## 772. Basic Calculator III + +=== "Python" + + ```python + --8<-- "0772_basic_calculator_iii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0772_basic_calculator_iii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0772_basic_calculator_iii.ts" + ``` + +## 770. Basic Calculator IV + +=== "Python" + + ```python + --8<-- "0770_basic_calculator_iv.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0770_basic_calculator_iv.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0770_basic_calculator_iv.ts" + ``` diff --git a/docs/leetpattern/stack_monotonic.md b/docs/leetpattern/stack_monotonic.md new file mode 100644 index 00000000..6d1b47f7 --- /dev/null +++ b/docs/leetpattern/stack_monotonic.md @@ -0,0 +1,224 @@ +--- +comments: True +--- + +# Stack Monotonic + +## 739. Daily Temperatures + +- Return an array `res` such that `res[i]` is the number of days you have to wait after the `ith` day to get a warmer temperature. + +| Index | Temp | > stack last | stack | result | +| ----- | ---- | ------------ | ------------------------------- | --------- | +| 0 | 73 | False | `[ [73, 0] ]` | 1 - 0 = 1 | +| 1 | 74 | True | `[ [74, 1] ]` | 2 - 1 = 1 | +| 2 | 75 | True | `[ [75, 2] ]` | 6 - 2 = 4 | +| 3 | 71 | False | `[ [75, 2], [71, 3] ]` | 5 - 3 = 2 | +| 4 | 69 | False | `[ [75, 2], [71, 3], [69, 4] ]` | 5 - 4 = 1 | +| 5 | 72 | True | `[ [75, 2], [72, 5] ]` | 6 - 5 = 1 | +| 6 | 76 | True | `[ [76, 6] ]` | 0 | +| 7 | 73 | False | `[[76, 6], [73, 7]]` | 0 | + +=== "Python" + + ```python + --8<-- "0739_daily_temperatures.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0739_daily_temperatures.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0739_daily_temperatures.ts" + ``` + +## 496. Next Greater Element I + +=== "Python" + + ```python + --8<-- "0496_next_greater_element_i.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0496_next_greater_element_i.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0496_next_greater_element_i.ts" + ``` + +## 503. Next Greater Element II + +=== "Python" + + ```python + --8<-- "0503_next_greater_element_ii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0503_next_greater_element_ii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0503_next_greater_element_ii.ts" + ``` + +## 84. Largest Rectangle in Histogram + +=== "Python" + + ```python + --8<-- "0084_largest_rectangle_in_histogram.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0084_largest_rectangle_in_histogram.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0084_largest_rectangle_in_histogram.ts" + ``` + +## 85. Maximal Rectangle + +- Return the area of the largest rectangle that can be formed within a rectangle of 1's. + +![0085](https://assets.leetcode.com/uploads/2020/09/14/maximal.jpg){width=300px} + +=== "Python" + + ```python + --8<-- "0085_maximal_rectangle.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0085_maximal_rectangle.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0085_maximal_rectangle.ts" + ``` + +## 42. Trapping Rain Water + +=== "Python" + + ```python + --8<-- "0042_trapping_rain_water.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0042_trapping_rain_water.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0042_trapping_rain_water.ts" + ``` + +## 901. Online Stock Span + +- Design a class `StockSpanner` to return the number of consecutive days (including the current day) the price of the stock has been less than or equal to the current price. + +=== "Python" + + ```python + --8<-- "0901_online_stock_span.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0901_online_stock_span.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0901_online_stock_span.ts" + ``` + +## 316. Remove Duplicate Letters + +=== "Python" + + ```python + --8<-- "0316_remove_duplicate_letters.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0316_remove_duplicate_letters.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0316_remove_duplicate_letters.ts" + ``` + +## 456. 132 Pattern + +=== "Python" + + ```python + --8<-- "0456_132_pattern.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0456_132_pattern.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0456_132_pattern.ts" + ``` + +## 2281. Sum of Total Strength of Wizards + +=== "Python" + + ```python + --8<-- "2281_sum_of_total_strength_of_wizards.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/2281_sum_of_total_strength_of_wizards.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/2281_sum_of_total_strength_of_wizards.ts" + ``` diff --git a/docs/leetpattern/tree_bfs.md b/docs/leetpattern/tree_bfs.md new file mode 100644 index 00000000..2874fe0a --- /dev/null +++ b/docs/leetpattern/tree_bfs.md @@ -0,0 +1,217 @@ +--- +comments: True +--- + +# Tree BFS + +## 199. Binary Tree Right Side View + +```plaintext + ____1 <--- + / \ + 2__ 2 <--- Look at the rightmost node at each level + / \ \ +3 4 3 <--- + / + 5 <--- +``` + +=== "Python" + + ```python + --8<-- "0199_binary_tree_right_side_view.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0199_binary_tree_right_side_view.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0199_binary_tree_right_side_view.ts" + ``` + +## 111. Minimum Depth of Binary Tree + +=== "Python" + + ```python + --8<-- "0111_minimum_depth_of_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0111_minimum_depth_of_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0111_minimum_depth_of_binary_tree.ts" + ``` + +## 104. Maximum Depth of Binary Tree + +=== "Python" + + ```python + --8<-- "0104_maximum_depth_of_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0104_maximum_depth_of_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0104_maximum_depth_of_binary_tree.ts" + ``` + +## 637. Average of Levels in Binary Tree + +=== "Python" + + ```python + --8<-- "0637_average_of_levels_in_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0637_average_of_levels_in_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0637_average_of_levels_in_binary_tree.ts" + ``` + +## 429. N-ary Tree Level Order Traversal + +=== "Python" + + ```python + --8<-- "0429_n_ary_tree_level_order_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0429_n_ary_tree_level_order_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0429_n_ary_tree_level_order_traversal.ts" + ``` + +## 515. Find Largest Value in Each Tree Row + +=== "Python" + + ```python + --8<-- "0515_find_largest_value_in_each_tree_row.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0515_find_largest_value_in_each_tree_row.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0515_find_largest_value_in_each_tree_row.ts" + ``` + +## 116. Populating Next Right Pointers in Each Node + +- Perfect Binary Tree + +=== "Python" + + ```python + --8<-- "0116_populating_next_right_pointers_in_each_node.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0116_populating_next_right_pointers_in_each_node.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0116_populating_next_right_pointers_in_each_node.ts" + ``` + +## 117. Populating Next Right Pointers in Each Node II + +=== "Python" + + ```python + --8<-- "0117_populating_next_right_pointers_in_each_node_ii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0117_populating_next_right_pointers_in_each_node_ii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0117_populating_next_right_pointers_in_each_node_ii.ts" + ``` + +## 513. Find Bottom Left Tree Value + +=== "Python" + + ```python + --8<-- "0513_find_bottom_left_tree_value.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0513_find_bottom_left_tree_value.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0513_find_bottom_left_tree_value.ts" + ``` + +## 863. All Nodes Distance K in Binary Tree + +=== "Python" + + ```python + --8<-- "0863_all_nodes_distance_k_in_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0863_all_nodes_distance_k_in_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0863_all_nodes_distance_k_in_binary_tree.ts" + ``` diff --git a/docs/leetpattern/tree_feature.md b/docs/leetpattern/tree_feature.md new file mode 100644 index 00000000..f550504f --- /dev/null +++ b/docs/leetpattern/tree_feature.md @@ -0,0 +1,205 @@ +--- +comments: True +--- + +# Tree Feature + +## 101. Symmetric Tree + +=== "Python" + + ```python + --8<-- "0101_symmetric_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0101_symmetric_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0101_symmetric_tree.ts" + ``` + +## 222. Count Complete Tree Nodes + +=== "Python" + + ```python + --8<-- "0222_count_complete_tree_nodes.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0222_count_complete_tree_nodes.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0222_count_complete_tree_nodes.ts" + ``` + +## 110. Balanced Binary Tree + +=== "Python" + + ```python + --8<-- "0110_balanced_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0110_balanced_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0110_balanced_binary_tree.ts" + ``` + +## 257. Binary Tree Paths + +=== "Python" + + ```python + --8<-- "0257_binary_tree_paths.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0257_binary_tree_paths.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0257_binary_tree_paths.ts" + ``` + +## 404. Sum of Left Leaves + +=== "Python" + + ```python + --8<-- "0404_sum_of_left_leaves.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0404_sum_of_left_leaves.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0404_sum_of_left_leaves.ts" + ``` + +## 112. Path Sum + +=== "Python" + + ```python + --8<-- "0112_path_sum.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0112_path_sum.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0112_path_sum.ts" + ``` + +## 2331. Evaluate Boolean Binary Tree + +=== "Python" + + ```python + --8<-- "2331_evaluate_boolean_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/2331_evaluate_boolean_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/2331_evaluate_boolean_binary_tree.ts" + ``` + +## 100. Same Tree + +=== "Python" + + ```python + --8<-- "0100_same_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0100_same_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0100_same_tree.ts" + ``` + +## 235. Lowest Common Ancestor of a Binary Search Tree + +=== "Python" + + ```python + --8<-- "0235_lowest_common_ancestor_of_a_binary_search_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0235_lowest_common_ancestor_of_a_binary_search_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0235_lowest_common_ancestor_of_a_binary_search_tree.ts" + ``` + +## 236. Lowest Common Ancestor of a Binary Tree + +=== "Python" + + ```python + --8<-- "0236_lowest_common_ancestor_of_a_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0236_lowest_common_ancestor_of_a_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0236_lowest_common_ancestor_of_a_binary_tree.ts" + ``` diff --git a/docs/leetpattern/tree_modification.md b/docs/leetpattern/tree_modification.md new file mode 100644 index 00000000..a6d81b34 --- /dev/null +++ b/docs/leetpattern/tree_modification.md @@ -0,0 +1,105 @@ +--- +comments: True +--- + +# Tree Modification + +## 226. Invert Binary Tree + +=== "Python" + + ```python + --8<-- "0226_invert_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0226_invert_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0226_invert_binary_tree.ts" + ``` + +## 105. Construct Binary Tree from Preorder and Inorder Traversal + +=== "Python" + + ```python + --8<-- "0105_construct_binary_tree_from_preorder_and_inorder_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0105_construct_binary_tree_from_preorder_and_inorder_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0105_construct_binary_tree_from_preorder_and_inorder_traversal.ts" + ``` + +## 106. Construct Binary Tree from Inorder and Postorder Traversal + +=== "Python" + + ```python + --8<-- "0106_construct_binary_tree_from_inorder_and_postorder_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0106_construct_binary_tree_from_inorder_and_postorder_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0106_construct_binary_tree_from_inorder_and_postorder_traversal.ts" + ``` + +## 654. Maximum Binary Tree + +=== "Python" + + ```python + --8<-- "0654_maximum_binary_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0654_maximum_binary_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0654_maximum_binary_tree.ts" + ``` + +## 617. Merge Two Binary Trees + +=== "Python" + + ```python + --8<-- "0617_merge_two_binary_trees.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0617_merge_two_binary_trees.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0617_merge_two_binary_trees.ts" + ``` diff --git a/docs/leetpattern/tree_traversal.md b/docs/leetpattern/tree_traversal.md new file mode 100644 index 00000000..c8b0bc69 --- /dev/null +++ b/docs/leetpattern/tree_traversal.md @@ -0,0 +1,248 @@ +--- +comments: True +--- + +# Tree Traversal + +## 144. Binary Tree Preorder Traversal + +![tree_traversal](../assets/tree_traversal_dfs_bfs.png) + +### Example 1 + +```mermaid +graph TD +A(( )) +B(( )) +C(( )) +D(( )) +E(( )) +F(( )) +G(( )) +A --- B +A --- E +B --- C +B --- D +E --- F +E --- G +``` + +Pre-order Traversal + +```mermaid +graph TD +0((0)) +1((1)) +2((2)) +3((3)) +4((4)) +5((5)) +6((6)) +0 --- 1 +0 --- 4 +1 --- 2 +1 --- 3 +4 --- 5 +4 --- 6 +``` + +In-order Traversal + +```mermaid +graph TD +0((0)) +1((1)) +2((2)) +3((3)) +4((4)) +5((5)) +6((6)) +3 --- 1 +3 --- 5 +1 --- 0 +1 --- 2 +5 --- 4 +5 --- 6 +``` + +Post-order Traversal + +```mermaid +graph TD +0((0)) +1((1)) +2((2)) +3((3)) +4((4)) +5((5)) +6((6)) +6 --- 2 +6 --- 5 +2 --- 0 +2 --- 1 +5 --- 3 +5 --- 4 +``` + +Level Order Traversal + +```mermaid +graph TD +0((0)) +1((1)) +2((1)) +3((2)) +4((2)) +5((2)) +6((2)) +0 --- 1 +0 --- 2 +1 --- 3 +1 --- 4 +2 --- 5 +2 --- 6 +``` + +### Example 2 + +```mermaid +graph TD +0((0)) +1((1)) +2((2)) +3((3)) +4((4)) +5((5)) +6((6)) +0 --- 1 +0 --- 2 +1 --- 3 +1 --- 4 +2 --- 5 +2 --- 6 +``` + +| Traversal | Order | Method | Result | +| ----------- | ----------------- | -------------- | ----------------------------- | +| Preorder | Root, Left, Right | DFS or Stack | `[0, 1, 3, 4, 2, 5, 6]` | +| Inorder | Left, Root, Right | DFS or Stack | `[3, 1, 4, 0, 5, 2, 6]` | +| Postorder | Left, Right, Root | DFS or Stack | `[3, 4, 1, 5, 6, 2, 0]` | +| Level Order | Level by Level | BFS with Queue | `[[0], [1, 2], [3, 4, 5, 6]]` | + +=== "Python" + + ```python + --8<-- "0144_binary_tree_preorder_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0144_binary_tree_preorder_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0144_binary_tree_preorder_traversal.ts" + ``` + +## 94. Binary Tree Inorder Traversal + +=== "Python" + + ```python + --8<-- "0094_binary_tree_inorder_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0094_binary_tree_inorder_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0094_binary_tree_inorder_traversal.ts" + ``` + +## 145. Binary Tree Postorder Traversal + +=== "Python" + + ```python + --8<-- "0145_binary_tree_postorder_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0145_binary_tree_postorder_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0145_binary_tree_postorder_traversal.ts" + ``` + +## 102. Binary Tree Level Order Traversal + +=== "Python" + + ```python + --8<-- "0102_binary_tree_level_order_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0102_binary_tree_level_order_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0102_binary_tree_level_order_traversal.ts" + ``` + +## 107. Binary Tree Level Order Traversal II + +=== "Python" + + ```python + --8<-- "0107_binary_tree_level_order_traversal_ii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0107_binary_tree_level_order_traversal_ii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0107_binary_tree_level_order_traversal_ii.ts" + ``` + +## 103. Binary Tree Zigzag Level Order Traversal + +=== "Python" + + ```python + --8<-- "0103_binary_tree_zigzag_level_order_traversal.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0103_binary_tree_zigzag_level_order_traversal.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0103_binary_tree_zigzag_level_order_traversal.ts" + ``` diff --git a/docs/leetpattern/trie.md b/docs/leetpattern/trie.md new file mode 100644 index 00000000..47437227 --- /dev/null +++ b/docs/leetpattern/trie.md @@ -0,0 +1,84 @@ +--- +comments: True +--- + +# Trie + +## 208. Implement Trie (Prefix Tree) + +## Trie + +- A trie is a tree-like data structure whose nodes store the letters of an alphabet. + +```mermaid +flowchart TD +Root(( )) +Root --- C1(("C")) +Root --- D((D)) +C1 --- A1(("A")) +A1 --- T1(("T")) +A1 --- R1(("R")) +A1 --- N((N)) +Root --- B1((B)) +B1 --- A2((A)) +A2 --- T2((T)) +A2 --- R2((R)) +``` + +=== "Python" + + ```python + --8<-- "0208_implement_trie_prefix_tree.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0208_implement_trie_prefix_tree.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0208_implement_trie_prefix_tree.ts" + ``` + +## 211. Design Add and Search Words Data Structure + +=== "Python" + + ```python + --8<-- "0211_design_add_and_search_words_data_structure.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0211_design_add_and_search_words_data_structure.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0211_design_add_and_search_words_data_structure.ts" + ``` + +## 212. Word Search II + +=== "Python" + + ```python + --8<-- "0212_word_search_ii.py" + ``` + +=== "C++" + + ```cpp + --8<-- "cpp/0212_word_search_ii.cc" + ``` + +=== "TypeScript" + + ```typescript + --8<-- "ts/0212_word_search_ii.ts" + ``` diff --git a/docs/neetcode150/advanced_graphs.md b/docs/neetcode150/advanced_graphs.md index ec461083..db4f83d4 100644 --- a/docs/neetcode150/advanced_graphs.md +++ b/docs/neetcode150/advanced_graphs.md @@ -86,6 +86,27 @@ MST ## 743. Network Delay Time +- Return the minimum time taken to reach all nodes in a network. + +```mermaid +graph LR +1((1)) +2((2)) +3((3)) +4((4)) +2 --> |1| 1 +2 --> |1| 3 +3 --> |1| 4 +``` + +- Shortest Path Problem: Find the shortest path between two vertices in a graph. +- Dijkstra's Algorithm + - Shortest path algorithm + - Weighted graph (non-negative weights) + - Data Structure: Heap; Hash Set + - Time Complexity: O(E \* logV) + - Space Complexity: O(V) + === "Python" ```python @@ -106,6 +127,10 @@ MST ## 778. Swim in Rising Water +- Return the minimum time when you can reach the target. + +![778](https://assets.leetcode.com/uploads/2021/06/29/swim2-grid-1.jpg) + === "Python" ```python @@ -126,6 +151,8 @@ MST ## 269. Alien Dictionary +- Return the correct order of characters in the alien language. + === "Python" ```python diff --git a/docs/neetcode150/graphs.md b/docs/neetcode150/graphs.md index 4a252772..6917fea5 100644 --- a/docs/neetcode150/graphs.md +++ b/docs/neetcode150/graphs.md @@ -172,6 +172,19 @@ comments: True - Return true if it is possible to finish all courses, otherwise return false. - Dependency relationships imply the topological sort algorithm. - Cycle detection +- Topological Sort + - DAG (Directed Acyclic Graph) + - Time complexity: O(V+E) + - Space complexity: O(V+E) + - Prerequisites: Indegree (Look at the problem [1557. Minimum Number of Vertices to Reach All Nodes](#1557-minimum-number-of-vertices-to-reach-all-nodes)) + - Indegree: Number of incoming edges to a vertex + - Applications: task scheduling, course scheduling, build systems, dependency resolution, compiler optimization, etc. + +![ts1](../assets/graph_ts1.png){width=300px} + +![ts2](../assets/graph_ts2.png){width=300px} + +Course to prerequisites mapping ```mermaid flowchart LR @@ -182,6 +195,7 @@ flowchart LR 1((1)) --> 4((4)) ``` +Prerequisites to course mapping ```mermaid flowchart LR @@ -215,8 +229,7 @@ Initialize | in-degree | 2 | 2 | 0 | 1 | 0 | - queue: `[2, 4]` - -Pop `2` from the queue +- pop `2` from the queue ```mermaid flowchart LR @@ -231,8 +244,7 @@ flowchart LR | in-degree | 1 | 2 | 0 | 1 | 0 | - queue: `[4]` - -Pop `4` from the queue +- pop `4` from the queue ```mermaid flowchart LR @@ -245,8 +257,7 @@ flowchart LR | in-degree | 1 | 1 | 0 | 0 | 0 | - queue: `[3]` - -Pop `3` from the queue +- pop `3` from the queue ```mermaid flowchart LR @@ -258,8 +269,7 @@ flowchart LR | in-degree | 1 | 0 | 0 | 0 | 0 | - queue: `[1]` - -Pop `1` from the queue +- pop `1` from the queue ```mermaid flowchart LR @@ -271,8 +281,8 @@ flowchart LR | in-degree | 0 | 0 | 0 | 0 | 0 | - queue: `[0]` - -Pop `0` from the queue +- pop `0` from the queue +- All courses are taken. Return `True`. === "Python" @@ -294,6 +304,10 @@ Pop `0` from the queue ## 210. Course Schedule II +- Return the ordering of courses you should take to finish all courses. If there are multiple valid answers, return any of them. + +![0207](../assets/0207.png){width=300px} + === "Python" ```python diff --git a/docs/neetcode150/stack.md b/docs/neetcode150/stack.md index d043464a..0e4942b1 100644 --- a/docs/neetcode150/stack.md +++ b/docs/neetcode150/stack.md @@ -6,6 +6,18 @@ comments: True ## 20. Valid Parentheses +- Determine if the input string is valid. +- Steps for the string `()[]{}`: + +| char | action | stack | +| ---- | ------ | ----- | +| `(` | push | "\(" | +| `)` | pop | "" | +| `[` | push | "\[" | +| `]` | pop | "" | +| `{` | push | "\{" | +| `}` | pop | "" | + === "Python" ```python @@ -26,6 +38,8 @@ comments: True ## 155. Min Stack +- Implement a stack that supports push, pop, top, and retrieving the minimum element in constant time. + === "Python" ```python @@ -46,6 +60,16 @@ comments: True ## 150. Evaluate Reverse Polish Notation +- Steps for the list `["2", "1", "+", "3", "*"]`: + +| token | action | stack | +| ----- | ------ | -------- | +| `2` | push | `[2]` | +| `1` | push | `[2, 1]` | +| `+` | pop | `[3]` | +| `3` | push | `[3, 3]` | +| `*` | pop | `[9]` | + === "Python" ```python @@ -86,6 +110,19 @@ comments: True ## 739. Daily Temperatures +- Return an array `res` such that `res[i]` is the number of days you have to wait after the `ith` day to get a warmer temperature. + +| Index | Temp | > stack last | stack | result | +| ----- | ---- | ------------ | ------------------------------- | --------- | +| 0 | 73 | False | `[ [73, 0] ]` | 1 - 0 = 1 | +| 1 | 74 | True | `[ [74, 1] ]` | 2 - 1 = 1 | +| 2 | 75 | True | `[ [75, 2] ]` | 6 - 2 = 4 | +| 3 | 71 | False | `[ [75, 2], [71, 3] ]` | 5 - 3 = 2 | +| 4 | 69 | False | `[ [75, 2], [71, 3], [69, 4] ]` | 5 - 4 = 1 | +| 5 | 72 | True | `[ [75, 2], [72, 5] ]` | 6 - 5 = 1 | +| 6 | 76 | True | `[ [76, 6] ]` | 0 | +| 7 | 73 | False | `[[76, 6], [73, 7]]` | 0 | + === "Python" ```python diff --git a/docs/neetcode150/trees.md b/docs/neetcode150/trees.md index 13d82579..0be35917 100644 --- a/docs/neetcode150/trees.md +++ b/docs/neetcode150/trees.md @@ -166,6 +166,16 @@ comments: True ## 199. Binary Tree Right Side View +```plaintext + ____1 <--- + / \ + 2__ 2 <--- Look at the rightmost node at each level + / \ \ +3 4 3 <--- + / + 5 <--- +``` + === "Python" ```python diff --git a/docs/neetcode150/tries.md b/docs/neetcode150/tries.md index e437cb0d..0a1e8644 100644 --- a/docs/neetcode150/tries.md +++ b/docs/neetcode150/tries.md @@ -6,6 +6,25 @@ comments: True ## 208. Implement Trie (Prefix Tree) +## Trie + +- A trie is a tree-like data structure whose nodes store the letters of an alphabet. + +```mermaid +flowchart TD +Root(( )) +Root --- C1(("C")) +Root --- D((D)) +C1 --- A1(("A")) +A1 --- T1(("T")) +A1 --- R1(("R")) +A1 --- N((N)) +Root --- B1((B)) +B1 --- A2((A)) +A2 --- T2((T)) +A2 --- R2((R)) +``` + === "Python" ```python diff --git a/mkdocs.yaml b/mkdocs.yaml index db249867..f55e77c7 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -1,133 +1,141 @@ nav: - - Home: README.md + - Home: README.md - - LeetPattern: - - Home: leetpattern/index.md - - Binary Search: leetpattern/binary_search.md - - Array: leetpattern/array.md - - Left Right Pointers: leetpattern/left_right_pointers.md - - Fast Slow Pointers: leetpattern/fast_slow_pointers.md - - Sliding Window Fixed: leetpattern/sliding_window_fixed.md - - Sliding Window Variable: leetpattern/sliding_window_variable.md - - Boyer Moore: leetpattern/boyer_moore.md - - Prefix Sum: leetpattern/prefix_sum.md - - Difference Array: leetpattern/difference_array.md - - Linked List: leetpattern/linked_list.md - - Backtracking: leetpattern/backtracking.md - - Hash Map: leetpattern/hash_map.md - - Hash Set: leetpattern/hash_set.md - - Hash Counting: leetpattern/hash_counting.md - - String: leetpattern/string.md - - KMP: leetpattern/kmp.md - - DP Basic: leetpattern/dp_basic.md - - DP 2D: leetpattern/dp_2d.md - - DP Stock: leetpattern/dp_stock.md - - DP 01 Knapsack: leetpattern/dp_01_knapsack.md - - DP Unbounded Knapsack: leetpattern/dp_unbounded_knapsack.md - - DP Kadane: leetpattern/dp_kadane.md - - DP Interval: leetpattern/dp_interval.md - - DP LCS: leetpattern/dp_lcs.md - - DP LIS: leetpattern/dp_lis.md - - Greedy: leetpattern/greedy.md - - Intervals: leetpattern/intervals.md - - Graph Flood Fill: leetpattern/graph_flood_fill.md - - Graph BFS: leetpattern/graph_bfs.md - - Graph Topological Sort: leetpattern/graph_topological_sort.md - - Graph Union Find: leetpattern/graph_union_find.md - - Graph Shortest Path: leetpattern/graph_shortest_path.md - - Graph Bellman Ford: leetpattern/graph_bellman_ford.md - - Graph Minimum Spanning Tree: leetpattern/graph_minimum_spanning_tree.md - - Graph Coloring: leetpattern/graph_coloring.md - - Graph Tarjan: leetpattern/graph_tarjan.md - - Heap: leetpattern/heap.md - - Heap Top K: leetpattern/heap_top_k.md - - Heap Two Heaps: leetpattern/heap_two_heaps.md - - Heap Merge K Sorted: leetpattern/heap_merge_k_sorted.md - - Bit Manipulation: leetpattern/bit_manipulation.md - - Math: leetpattern/math.md - - Simulation: leetpattern/simulation.md - - Design: leetpattern/design.md + - Grind 75: + - Home: grind75/index.md + - Array: grind75/array.md + - Stack: grind75/stack.md + - Linked List: grind75/linked_list.md + - String: grind75/string.md + - Binary Tree: grind75/binary_tree.md + - Binary Search: grind75/binary_search.md + - Graph: grind75/graph.md + - Binary Search Tree: grind75/binary_search_tree.md + - Hash Table: grind75/hash_table.md + - Dynamic Programming: grind75/dynamic_programming.md + - Binary: grind75/binary.md + - Heap: grind75/heap.md + - Trie: grind75/trie.md + - Recursion: grind75/recursion.md + - Matrix: grind75/matrix.md - - SQL: - - Home: sql/index.md - - SQL 50: sql/sql50.md + - Neetcode 150: + - Home: neetcode150/index.md + - Arrays Hashing: neetcode150/arrays_hashing.md + - Two Pointers: neetcode150/two_pointers.md + - Sliding Window: neetcode150/sliding_window.md + - Stack: neetcode150/stack.md + - Binary Search: neetcode150/binary_search.md + - Linked List: neetcode150/linked_list.md + - Trees: neetcode150/trees.md + - Heap: neetcode150/heap.md + - Backtracking: neetcode150/backtracking.md + - Tries: neetcode150/tries.md + - Graphs: neetcode150/graphs.md + - Advanced Graphs: neetcode150/advanced_graphs.md + - 1D Dynamic Programming: neetcode150/1d_dynamic_programming.md + - 2D Dynamic_Programming: neetcode150/2d_dynamic_programming.md + - Greedy: neetcode150/greedy.md + - Intervals: neetcode150/intervals.md + - Math Geometry: neetcode150/math_geometry.md + - Bit Manipulation: neetcode150/bit_manipulation.md - - Grind 75: - - Home: grind75/index.md - - Array: grind75/array.md - - Stack: grind75/stack.md - - Linked List: grind75/linked_list.md - - String: grind75/string.md - - Binary Tree: grind75/binary_tree.md - - Binary Search: grind75/binary_search.md - - Graph: grind75/graph.md - - Binary Search Tree: grind75/binary_search_tree.md - - Hash Table: grind75/hash_table.md - - Dynamic Programming: grind75/dynamic_programming.md - - Binary: grind75/binary.md - - Heap: grind75/heap.md - - Trie: grind75/trie.md - - Recursion: grind75/recursion.md - - Matrix: grind75/matrix.md + - LeetPattern: + - Home: leetpattern/index.md + - Binary Search: leetpattern/binary_search.md + - Array: leetpattern/array.md + - Left Right Pointers: leetpattern/left_right_pointers.md + - Fast Slow Pointers: leetpattern/fast_slow_pointers.md + - Sliding Window Fixed: leetpattern/sliding_window_fixed.md + - Sliding Window Variable: leetpattern/sliding_window_variable.md + - Boyer Moore: leetpattern/boyer_moore.md + - Prefix Sum: leetpattern/prefix_sum.md + - Difference Array: leetpattern/difference_array.md + - Linked List: leetpattern/linked_list.md + - Backtracking: leetpattern/backtracking.md + - Hash Map: leetpattern/hash_map.md + - Hash Set: leetpattern/hash_set.md + - Hash Counting: leetpattern/hash_counting.md + - String: leetpattern/string.md + - KMP: leetpattern/kmp.md + - Tree Traversal: leetpattern/tree_traversal.md + - Tree Feature: leetpattern/tree_feature.md + - Tree BFS: leetpattern/tree_bfs.md + - Tree Modification: leetpattern/tree_modification.md + - BST: leetpattern/bst.md + - Trie: leetpattern/trie.md + - Stack: leetpattern/stack.md + - Stack Monotonic: leetpattern/stack_monotonic.md + - Queue: leetpattern/queue.md + - Queue Monotonic: leetpattern/queue_monotonic.md + - DP Basic: leetpattern/dp_basic.md + - DP 2D: leetpattern/dp_2d.md + - DP Stock: leetpattern/dp_stock.md + - DP 01 Knapsack: leetpattern/dp_01_knapsack.md + - DP Unbounded Knapsack: leetpattern/dp_unbounded_knapsack.md + - DP Kadane: leetpattern/dp_kadane.md + - DP Interval: leetpattern/dp_interval.md + - DP LCS: leetpattern/dp_lcs.md + - DP LIS: leetpattern/dp_lis.md + - Greedy: leetpattern/greedy.md + - Intervals: leetpattern/intervals.md + - Graph Flood Fill: leetpattern/graph_flood_fill.md + - Graph BFS: leetpattern/graph_bfs.md + - Graph Topological Sort: leetpattern/graph_topological_sort.md + - Graph Union Find: leetpattern/graph_union_find.md + - Graph Shortest Path: leetpattern/graph_shortest_path.md + - Graph Bellman Ford: leetpattern/graph_bellman_ford.md + - Graph Minimum Spanning Tree: leetpattern/graph_minimum_spanning_tree.md + - Graph Coloring: leetpattern/graph_coloring.md + - Graph Tarjan: leetpattern/graph_tarjan.md + - Heap: leetpattern/heap.md + - Heap Top K: leetpattern/heap_top_k.md + - Heap Two Heaps: leetpattern/heap_two_heaps.md + - Heap Merge K Sorted: leetpattern/heap_merge_k_sorted.md + - Bit Manipulation: leetpattern/bit_manipulation.md + - Math: leetpattern/math.md + - Simulation: leetpattern/simulation.md + - Design: leetpattern/design.md - - Neetcode 150: - - Home: neetcode150/index.md - - Arrays Hashing: neetcode150/arrays_hashing.md - - Two Pointers: neetcode150/two_pointers.md - - Sliding Window: neetcode150/sliding_window.md - - Stack: neetcode150/stack.md - - Binary Search: neetcode150/binary_search.md - - Linked List: neetcode150/linked_list.md - - Trees: neetcode150/trees.md - - Heap: neetcode150/heap.md - - Backtracking: neetcode150/backtracking.md - - Tries: neetcode150/tries.md - - Graphs: neetcode150/graphs.md - - Advanced Graphs: neetcode150/advanced_graphs.md - - 1D Dynamic Programming: neetcode150/1d_dynamic_programming.md - - 2D Dynamic_Programming: neetcode150/2d_dynamic_programming.md - - Greedy: neetcode150/greedy.md - - Intervals: neetcode150/intervals.md - - Math Geometry: neetcode150/math_geometry.md - - Bit Manipulation: neetcode150/bit_manipulation.md + - Blind 75: + - Home: blind75/index.md + - Arrays Hashing: blind75/arrays_hashing.md + - Two Pointers: blind75/two_pointers.md + - Sliding Window: blind75/sliding_window.md + - Stack: blind75/stack.md + - Binary Search: blind75/binary_search.md + - Linked List: blind75/linked_list.md + - Trees: blind75/trees.md + - Heap: blind75/heap.md + - Backtracking: blind75/backtracking.md + - Tries: blind75/tries.md + - Graphs: blind75/graphs.md + - Advanced Graphs: blind75/advanced_graphs.md + - 1D Dynamic Programming: blind75/1d_dynamic_programming.md + - 2D Dynamic Programming: blind75/2d_dynamic_programming.md + - Greedy: blind75/greedy.md + - Intervals: blind75/intervals.md + - Math Geometry: blind75/math_geometry.md + - Bit Manipulation: blind75/bit_manipulation.md - - Blind 75: - - Home: blind75/index.md - - Arrays Hashing: blind75/arrays_hashing.md - - Two Pointers: blind75/two_pointers.md - - Sliding Window: blind75/sliding_window.md - - Stack: blind75/stack.md - - Binary Search: blind75/binary_search.md - - Linked List: blind75/linked_list.md - - Trees: blind75/trees.md - - Heap: blind75/heap.md - - Backtracking: blind75/backtracking.md - - Tries: blind75/tries.md - - Graphs: blind75/graphs.md - - Advanced Graphs: blind75/advanced_graphs.md - - 1D Dynamic Programming: blind75/1d_dynamic_programming.md - - 2D Dynamic Programming: blind75/2d_dynamic_programming.md - - Greedy: blind75/greedy.md - - Intervals: blind75/intervals.md - - Math Geometry: blind75/math_geometry.md - - Bit Manipulation: blind75/bit_manipulation.md + - Company: + - Home: company/index.md + - Amazon: company/amazon.md - - Graph Theory: - - Home: graph_theory/index.md - - Standard Traversal: graph_theory/standard_traversal.md - - BFS: graph_theory/bfs.md - - Matrix Graphs: graph_theory/matrix_graphs.md - - Graph Theory: graph_theory/graph_theory.md - - Union Find: graph_theory/union_find.md - - Topological Sort: graph_theory/topological_sort.md - - Dijkstra's: graph_theory/dijkstra's.md - - MST: graph_theory/mst.md - - - Company: - - Home: company/index.md - - Amazon: company/amazon.md - - - About: about.md + - Graph Theory: + - Home: graph_theory/index.md + - Standard Traversal: graph_theory/standard_traversal.md + - BFS: graph_theory/bfs.md + - Matrix Graphs: graph_theory/matrix_graphs.md + - Graph Theory: graph_theory/graph_theory.md + - Union Find: graph_theory/union_find.md + - Topological Sort: graph_theory/topological_sort.md + - Dijkstra's: graph_theory/dijkstra's.md + - MST: graph_theory/mst.md + - SQL: + - Home: sql/index.md + - SQL 50: sql/sql50.md + - About: about.md ############################################## ## Material theme configuration for MkDocs ## @@ -141,134 +149,134 @@ repo_url: https://github.com/russhustle/leetpattern/ copyright: Copyright © 2024-2025 Sihan A theme: - language: en - logo: assets/logo.jpg - favicon: assets/logo.jpg - name: material - palette: - - media: "(prefers-color-scheme: dark)" - scheme: slate - primary: indigo - accent: pink - toggle: - icon: material/toggle-switch - name: Switch to system preference - - media: "(prefers-color-scheme: light)" - scheme: default - primary: indigo - accent: pink - toggle: - icon: material/toggle-switch-off-outline - name: Switch to dark mode + language: en + logo: assets/logo.jpg + favicon: assets/logo.jpg + name: material + palette: + - media: "(prefers-color-scheme: dark)" + scheme: slate + primary: indigo + accent: pink + toggle: + icon: material/toggle-switch + name: Switch to system preference + - media: "(prefers-color-scheme: light)" + scheme: default + primary: indigo + accent: pink + toggle: + icon: material/toggle-switch-off-outline + name: Switch to dark mode - font: - text: Open Sans - code: Roboto Mono + font: + text: Open Sans + code: Roboto Mono - features: - - content.code.copy # Enable copy button on code blocks - - content.code.select # Enable select button on code blocks - - content.tabs.link # Enable link button on tabs - # - navigation.tabs - - navigation.tracking - - navigation.tabs.sticky - - navigation.indexes # Enable indexes for the navigation - - navigation.instant - - navigation.instant.prefetch - - navigation.instant.progress - - navigation.path - - navigation.footer # Enable footer navigation - - navigation.top - - search.suggest # Enable search suggestions - - search.highlight # Enable search term highlighting - - content.math - - grid - - toc.follow - icon: - previous: fontawesome/solid/angle-left - next: fontawesome/solid/angle-right - admonition: - note: octicons/tag-16 - abstract: octicons/checklist-16 - info: octicons/info-16 - tip: octicons/squirrel-16 - success: octicons/check-16 - question: octicons/question-16 - warning: octicons/alert-16 - failure: octicons/x-circle-16 - danger: octicons/zap-16 - bug: octicons/bug-16 - example: octicons/beaker-16 - quote: octicons/quote-16 - custom_dir: overrides + features: + - content.code.copy # Enable copy button on code blocks + - content.code.select # Enable select button on code blocks + - content.tabs.link # Enable link button on tabs + # - navigation.tabs + - navigation.tracking + - navigation.tabs.sticky + - navigation.indexes # Enable indexes for the navigation + - navigation.instant + - navigation.instant.prefetch + - navigation.instant.progress + - navigation.path + - navigation.footer # Enable footer navigation + - navigation.top + - search.suggest # Enable search suggestions + - search.highlight # Enable search term highlighting + - content.math + - grid + - toc.follow + icon: + previous: fontawesome/solid/angle-left + next: fontawesome/solid/angle-right + admonition: + note: octicons/tag-16 + abstract: octicons/checklist-16 + info: octicons/info-16 + tip: octicons/squirrel-16 + success: octicons/check-16 + question: octicons/question-16 + warning: octicons/alert-16 + failure: octicons/x-circle-16 + danger: octicons/zap-16 + bug: octicons/bug-16 + example: octicons/beaker-16 + quote: octicons/quote-16 + custom_dir: overrides markdown_extensions: - - admonition - - pymdownx.details - - pymdownx.tabbed: - alternate_style: true - - pymdownx.snippets: - base_path: src - - pymdownx.highlight: - anchor_linenums: true - line_spans: __span - pygments_lang_class: true - - pymdownx.critic # CriticMarkup support - - pymdownx.caret # Caret Markup support - - pymdownx.keys - - pymdownx.mark - - pymdownx.tilde - - pymdownx.inlinehilite - - pymdownx.superfences: - custom_fences: - - name: mermaid - class: mermaid - - pymdownx.tasklist: - custom_checkbox: true - - pymdownx.arithmatex: - # latex support - generic: true - - toc: - permalink: true # Add permalinks to headers - - attr_list - - md_in_html + - admonition + - pymdownx.details + - pymdownx.tabbed: + alternate_style: true + - pymdownx.snippets: + base_path: src + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.critic # CriticMarkup support + - pymdownx.caret # Caret Markup support + - pymdownx.keys + - pymdownx.mark + - pymdownx.tilde + - pymdownx.inlinehilite + - pymdownx.superfences: + custom_fences: + - name: mermaid + class: mermaid + - pymdownx.tasklist: + custom_checkbox: true + - pymdownx.arithmatex: + # latex support + generic: true + - toc: + permalink: true # Add permalinks to headers + - attr_list + - md_in_html plugins: - # show the last modification date of the page - - git-revision-date-localized: - enable_creation_date: true - type: timeago - - search + # show the last modification date of the page + - git-revision-date-localized: + enable_creation_date: true + type: timeago + - search extra: - creator: Sihan A - homepage: https://www.leetpattern.com - social: - - icon: fontawesome/brands/github - link: https://github.com/russhustle - name: GitHub | Sihan A - - icon: fontawesome/brands/linkedin - link: https://www.linkedin.com/in/sihan-a/ - name: LinkedIn | Sihan A - - icon: fontawesome/brands/kaggle - link: https://www.kaggle.com/sihana - name: Kaggle | Sihan A - - icon: fontawesome/brands/medium - link: https://medium.com/@sihan-a - name: Medium | Sihan A - consent: - title: Cookie consent - description: We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better. + creator: Sihan A + homepage: https://www.leetpattern.com + social: + - icon: fontawesome/brands/github + link: https://github.com/russhustle + name: GitHub | Sihan A + - icon: fontawesome/brands/linkedin + link: https://www.linkedin.com/in/sihan-a/ + name: LinkedIn | Sihan A + - icon: fontawesome/brands/kaggle + link: https://www.kaggle.com/sihana + name: Kaggle | Sihan A + - icon: fontawesome/brands/medium + link: https://medium.com/@sihan-a + name: Medium | Sihan A + consent: + title: Cookie consent + description: We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better. - analytics: - provider: google - property: G-EZ5J5E3CTR + analytics: + provider: google + property: G-EZ5J5E3CTR extra_javascript: - - utils/mathjax.js - - https://polyfill.io/v3/polyfill.min.js?features=es6 - - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js + - utils/mathjax.js + - https://polyfill.io/v3/polyfill.min.js?features=es6 + - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js extra_css: - - utils/unordered-list-symbols.css - - utils/ordered-list-symbols.css - - utils/table.css + - utils/unordered-list-symbols.css + - utils/ordered-list-symbols.css + - utils/table.css