Skip to content

Commit a3b1b89

Browse files
Zanger67/leetcodeZanger67/leetcode
authored andcommitted
Updated markdown files
1 parent 9588277 commit a3b1b89

File tree

11 files changed

+75
-21
lines changed

11 files changed

+75
-21
lines changed

markdowns/Medium.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
| 781 | [Rabbits in Forest](<https://leetcode.com/problems/rabbits-in-forest>) | Medium | Daily | [solution](<_781. Rabbits in Forest.md>) | py | Apr 21, 2025 |
155155
| 784 | [Letter Case Permutation](<https://leetcode.com/problems/letter-case-permutation>) | Medium | | [solution](<_784. Letter Case Permutation.md>) | py | Jun 15, 2024 |
156156
| 791 | [Custom Sort String](<https://leetcode.com/problems/custom-sort-string>) | Medium | | [solution](<_791. Custom Sort String.md>) | java | Jun 24, 2024 |
157-
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 26, 2025 |
157+
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 27, 2025 |
158158
| 794 | [Valid Tic-Tac-Toe State](<https://leetcode.com/problems/valid-tic-tac-toe-state>) | Medium | | [solution](<_794. Valid Tic-Tac-Toe State.md>) | py | Jul 05, 2024 |
159159
| 797 | [All Paths From Source to Target](<https://leetcode.com/problems/all-paths-from-source-to-target>) | Medium | | [solution](<_797. All Paths From Source to Target.md>) | py | Mar 05, 2025 |
160160
| 807 | [Max Increase to Keep City Skyline](<https://leetcode.com/problems/max-increase-to-keep-city-skyline>) | Medium | | [solution](<_807. Max Increase to Keep City Skyline.md>) | java | Jun 22, 2024 |

markdowns/Questions_By_Code_Length.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Calculations are based on the code files's byte sizes.
3939
| 431 | [Encode N-ary Tree to Binary Tree](<https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree>) | Hard | | [solution](<_431. Encode N-ary Tree to Binary Tree.md>) | java, py | Jun 28, 2024 |
4040
| 480 | [Sliding Window Median](<https://leetcode.com/problems/sliding-window-median>) | Hard | | [solution](<_480. Sliding Window Median.md>) | py | Sep 25, 2024 |
4141
| 224 | [Basic Calculator](<https://leetcode.com/problems/basic-calculator>) | Hard | | [solution](<_224. Basic Calculator.md>) | py | Jun 10, 2024 |
42+
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 27, 2025 |
4243
| 19 | [Remove Nth Node From End of List](<https://leetcode.com/problems/remove-nth-node-from-end-of-list>) | Medium | B75, N150 | [solution](<_19. Remove Nth Node From End of List.md>) | c, java, py | Jun 07, 2024 |
4344
| 114 | [Flatten Binary Tree to Linked List](<https://leetcode.com/problems/flatten-binary-tree-to-linked-list>) | Medium | | [solution](<_114. Flatten Binary Tree to Linked List.md>) | c, py | Jun 11, 2024 |
4445
| 987 | [Vertical Order Traversal of a Binary Tree](<https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree>) | Hard | | [solution](<_987. Vertical Order Traversal of a Binary Tree.md>) | py | Jun 12, 2024 |
@@ -98,7 +99,6 @@ Calculations are based on the code files's byte sizes.
9899
| 1368 | [Minimum Cost to Make at Least One Valid Path in a Grid](<https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid>) | Hard | Daily | [solution](<_1368. Minimum Cost to Make at Least One Valid Path in a Grid.md>) | py | Jan 18, 2025 |
99100
| 1609 | [Even Odd Tree](<https://leetcode.com/problems/even-odd-tree>) | Medium | | [solution](<_1609. Even Odd Tree.md>) | py | Jul 05, 2024 |
100101
| 13 | [Roman to Integer](<https://leetcode.com/problems/roman-to-integer>) | Easy | | [solution](<_13. Roman to Integer.md>) | py | Jul 31, 2024 |
101-
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 26, 2025 |
102102
| 2493 | [Divide Nodes Into the Maximum Number of Groups](<https://leetcode.com/problems/divide-nodes-into-the-maximum-number-of-groups>) | Hard | Daily | [solution](<_2493. Divide Nodes Into the Maximum Number of Groups.md>) | py | Jan 30, 2025 |
103103
| 437 | [Path Sum III](<https://leetcode.com/problems/path-sum-iii>) | Medium | | [solution](<_437. Path Sum III.md>) | py | Jul 03, 2024 |
104104
| 616 | [Add Bold Tag in String](<https://leetcode.com/problems/add-bold-tag-in-string>) | Medium | | [solution](<_616. Add Bold Tag in String.md>) | py | Jun 28, 2024 |

markdowns/Questions_By_Recent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Calculations are based on the date of the first solve.
66

77
| # | Title | Level | Cats | Solution | Languages | Date Complete |
88
|-----:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:--------------------------|:----------------------------------------------------------------------------------------------------|:--------------------------------------------|:----------------|
9-
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 26, 2025 |
9+
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<_792. Number of Matching Subsequences.md>) | py | Aug 27, 2025 |
1010
| 1198 | [Find Smallest Common Element in All Rows](<https://leetcode.com/problems/find-smallest-common-element-in-all-rows>) | Medium | | [solution](<_1198. Find Smallest Common Element in All Rows.md>) | py | Aug 26, 2025 |
1111
| 3000 | [Maximum Area of Longest Diagonal Rectangle](<https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle>) | Easy | Daily | [solution](<_3000. Maximum Area of Longest Diagonal Rectangle.md>) | py | Aug 26, 2025 |
1212
| 498 | [Diagonal Traverse](<https://leetcode.com/problems/diagonal-traverse>) | Medium | Daily | [solution](<_498. Diagonal Traverse.md>) | go, py | Aug 25, 2025 |

markdowns/_792. Number of Matching Subsequences.md

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
------
88

9-
> *First completed : August 26, 2025*
9+
> *First completed : August 27, 2025*
1010
>
11-
> *Last updated : August 26, 2025*
11+
> *Last updated : August 27, 2025*
1212
1313
------
1414

@@ -18,11 +18,28 @@
1818
1919
------
2020

21+
> ## V1 DFS Parallel Index Tracking
22+
>
23+
> Indexes the indices of each character in `s` and creates a trie of
24+
> all potential subsequence words. Then, performs a DFS on the subsequence word trie while tracking the "last used index" of each character to see if each is valid.
25+
>
26+
> Runtime: $O(s+w*v*s)$ where $s$ is the length of input string `s` and $w$ is the number of subsequence candidates in `words` and $v$ is the longest candidate in `words`.
27+
>
28+
> ## V2 Trie-Merging Recursion
29+
>
30+
> Converts potential subsequence word targets into a trie then iterates through each character of `s`. At each character `c`, if it's in the trie, we remove it and merge the subtrie into the main trie root. That is, we merge `trie[c]` into the root `trie` and recursively merge the branches. We use `trie['.']` to track how many word "endings" we have. Since we're systematically eliminating letters and summing `trie['.']` we return `'.'` which is our counter.
31+
>
32+
> Runtime: $O(s)$ where $s$ is the length of the input string `s`.
33+
>
34+
35+
------
36+
2137
## Solutions
2238

23-
- [m792 v1.py](<../my-submissions/m792 v1.py>)
39+
- [m792 v1 dfs parallel index tracking.py](<../my-submissions/m792 v1 dfs parallel index tracking.py>)
40+
- [m792 v2 triemerging optimized.py](<../my-submissions/m792 v2 triemerging optimized.py>)
2441
### Python
25-
#### [m792 v1.py](<../my-submissions/m792 v1.py>)
42+
#### [m792 v1 dfs parallel index tracking.py](<../my-submissions/m792 v1 dfs parallel index tracking.py>)
2643
```Python
2744
class Solution:
2845
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
@@ -56,9 +73,8 @@ class Solution:
5673
continue
5774
if nxt_c == "." :
5875
continue
59-
6076
char_ord = ord(nxt_c) - ord('a')
61-
previous_rec = c_indxes[char_ord]
77+
prev_reset = c_indxes[char_ord]
6278

6379
if c_indxes[char_ord] >= len(s_indxes[nxt_c]) :
6480
continue
@@ -69,18 +85,56 @@ class Solution:
6985
break
7086

7187
if c_indxes[char_ord] >= len(s_indxes[nxt_c]) :
72-
c_indxes[char_ord] = previous_rec
88+
c_indxes[char_ord] = prev_reset
7389
continue
7490

7591
c_indxes[char_ord] += 1
7692
output += self._dfs_trie(
77-
nxt_trie,
78-
s_indxes,
79-
c_indxes,
93+
nxt_trie,
94+
s_indxes,
95+
c_indxes,
8096
s_indxes[nxt_c][c_indxes[char_ord] - 1] + 1
8197
)
82-
c_indxes[char_ord] = previous_rec
98+
c_indxes[char_ord] = prev_reset
8399

84100
return output
85101
```
86102

103+
#### [m792 v2 triemerging optimized.py](<../my-submissions/m792 v2 triemerging optimized.py>)
104+
```Python
105+
class Solution:
106+
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
107+
trie = {}
108+
for w in words :
109+
curr = trie
110+
for c in w :
111+
if c not in curr :
112+
curr[c] = {}
113+
curr = curr[c]
114+
# Mark ends of words; +1 in case there are repeats
115+
curr["."] = curr.get(".", 0) + 1
116+
117+
for c in s :
118+
if c not in trie :
119+
continue
120+
# Remove the char branch and merge its subtrie contents into main trie
121+
self._trie_merger_helper(trie, trie.pop(c))
122+
123+
return trie['.']
124+
125+
def _trie_merger_helper(self, trie1: Dict[str, dict], trie2: Dict[str, dict]) -> None :
126+
# Merge our "success" counter
127+
if '.' in trie2 :
128+
trie1['.'] = trie1.get('.', 0) + trie2.get('.', 0)
129+
trie2.pop('.')
130+
131+
# Merge branches of trie
132+
for k, v in trie2.items() :
133+
if k not in trie1 : # If doesn't exist, we can reuse directly
134+
trie1[k] = v
135+
continue
136+
137+
# Recurse into branches
138+
self._trie_merger_helper(trie1[k], trie2[k])
139+
```
140+

markdowns/by_topic/Array.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
| 746 | [Min Cost Climbing Stairs](<https://leetcode.com/problems/min-cost-climbing-stairs>) | Easy | N150 | [solution](<../_746. Min Cost Climbing Stairs.md>) | py | Jul 05, 2024 |
101101
| 758 | [Bold Words in String](<https://leetcode.com/problems/bold-words-in-string>) | Medium | | [solution](<../_758. Bold Words in String.md>) | py | Jun 28, 2024 |
102102
| 781 | [Rabbits in Forest](<https://leetcode.com/problems/rabbits-in-forest>) | Medium | Daily | [solution](<../_781. Rabbits in Forest.md>) | py | Apr 21, 2025 |
103-
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<../_792. Number of Matching Subsequences.md>) | py | Aug 26, 2025 |
103+
| 792 | [Number of Matching Subsequences](<https://leetcode.com/problems/number-of-matching-subsequences>) | Medium | | [solution](<../_792. Number of Matching Subsequences.md>) | py | Aug 27, 2025 |
104104
| 794 | [Valid Tic-Tac-Toe State](<https://leetcode.com/problems/valid-tic-tac-toe-state>) | Medium | | [solution](<../_794. Valid Tic-Tac-Toe State.md>) | py | Jul 05, 2024 |
105105
| 807 | [Max Increase to Keep City Skyline](<https://leetcode.com/problems/max-increase-to-keep-city-skyline>) | Medium | | [solution](<../_807. Max Increase to Keep City Skyline.md>) | java | Jun 22, 2024 |
106106
| 817 | [Linked List Components](<https://leetcode.com/problems/linked-list-components>) | Medium | | [solution](<../_817. Linked List Components.md>) | java | Jul 04, 2024 |

0 commit comments

Comments
 (0)