@scurrlin/stencil 1.5.3 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -91
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,114 +14,48 @@ Whether you are studying for technical interviews, or just starting your coding
|
|
|
14
14
|
|
|
15
15
|
Most people when they attempt to memorize something study the full text and then attempt to regurgitate it on a blank page. Shocking, I know... but what if there was a step in between? What if memorization and pattern recognition weren't all or nothing games? This is where Stencil comes in.
|
|
16
16
|
|
|
17
|
-
Stencil is a language-agnostic memorization tool that strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized and fully memorized. Below is an example of Stencil in action using LeetCode problem
|
|
17
|
+
Stencil is a language-agnostic memorization tool that strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized and fully memorized. Below is an example of Stencil in action using LeetCode problem 32 "Longest Valid Parentheses":
|
|
18
18
|
|
|
19
19
|
## Example
|
|
20
20
|
|
|
21
21
|
Solution
|
|
22
22
|
|
|
23
23
|
```python
|
|
24
|
-
from collections import defaultdict
|
|
25
|
-
from typing import List
|
|
26
|
-
|
|
27
24
|
class Solution:
|
|
28
|
-
def
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
word_len = len(words[0])
|
|
33
|
-
count_words = len(words)
|
|
34
|
-
total_len = word_len * count_words
|
|
35
|
-
|
|
36
|
-
if len(s) < total_len:
|
|
37
|
-
return []
|
|
38
|
-
word_count = defaultdict(int)
|
|
39
|
-
for w in words:
|
|
40
|
-
word_count[w] += 1
|
|
41
|
-
result = []
|
|
25
|
+
def longestValidParentheses(self, s: str) -> int:
|
|
26
|
+
max_len = 0
|
|
27
|
+
stack = [-1]
|
|
42
28
|
|
|
43
|
-
for
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
seen_count[current_word] += 1
|
|
51
|
-
if seen_count[current_word] <= word_count[current_word]:
|
|
52
|
-
matched_words += 1
|
|
53
|
-
else:
|
|
54
|
-
while seen_count[current_word] > word_count[current_word]:
|
|
55
|
-
left_word = s[left : left + word_len]
|
|
56
|
-
seen_count[left_word] -= 1
|
|
57
|
-
if seen_count[left_word] < word_count[left_word]:
|
|
58
|
-
matched_words -= 1
|
|
59
|
-
left += word_len
|
|
60
|
-
if matched_words == count_words:
|
|
61
|
-
result.append(left)
|
|
62
|
-
left_word = s[left : left + word_len]
|
|
63
|
-
seen_count[left_word] -= 1
|
|
64
|
-
if seen_count[left_word] < word_count[left_word]:
|
|
65
|
-
matched_words -= 1
|
|
66
|
-
left += word_len
|
|
29
|
+
for i, char in enumerate(s):
|
|
30
|
+
if char == '(':
|
|
31
|
+
stack.append(i)
|
|
32
|
+
else:
|
|
33
|
+
stack.pop()
|
|
34
|
+
if not stack:
|
|
35
|
+
stack.append(i)
|
|
67
36
|
else:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
left = right + word_len
|
|
71
|
-
return result
|
|
37
|
+
max_len = max(max_len, i - stack[-1])
|
|
38
|
+
return max_len
|
|
72
39
|
```
|
|
73
40
|
|
|
74
41
|
Solution with Stencil
|
|
75
42
|
|
|
76
43
|
```python
|
|
77
|
-
f c i d
|
|
78
|
-
f t i L
|
|
79
|
-
|
|
80
44
|
c S:
|
|
81
|
-
d
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
w_l = l(w[0])
|
|
86
|
-
c_w = l(w)
|
|
87
|
-
t_l = w_l * c_w
|
|
88
|
-
|
|
89
|
-
i l(s) < t_l:
|
|
90
|
-
r []
|
|
91
|
-
w_c = d(i)
|
|
92
|
-
f w i w:
|
|
93
|
-
w_c[w] += 1
|
|
94
|
-
r = []
|
|
45
|
+
d l(s, s: s) -> i:
|
|
46
|
+
m_l = 0
|
|
47
|
+
s = [-1]
|
|
95
48
|
|
|
96
|
-
f
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
s_c[c_w] += 1
|
|
104
|
-
i s_c[c_w] <= w_c[c_w]:
|
|
105
|
-
m_w += 1
|
|
106
|
-
e:
|
|
107
|
-
w s_c[c_w] > w_c[c_w]:
|
|
108
|
-
l_w = s[l : l + w_l]
|
|
109
|
-
s_c[l_w] -= 1
|
|
110
|
-
i s_c[l_w] < w_c[l_w]:
|
|
111
|
-
m_w -= 1
|
|
112
|
-
l += w_l
|
|
113
|
-
i m_w == c_w:
|
|
114
|
-
r.a(l)
|
|
115
|
-
l_w = s[l : l + w_l]
|
|
116
|
-
s_c[l_w] -= 1
|
|
117
|
-
i s_c[l_w] < w_c[l_w]:
|
|
118
|
-
m_w -= 1
|
|
119
|
-
l += w_l
|
|
49
|
+
f i, c i e(s):
|
|
50
|
+
i c == '(':
|
|
51
|
+
s.a(i)
|
|
52
|
+
e:
|
|
53
|
+
s.p()
|
|
54
|
+
i n s:
|
|
55
|
+
s.a(i)
|
|
120
56
|
e:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
l = r + w_l
|
|
124
|
-
r r
|
|
57
|
+
m_l = m(m_l, i - s[-1])
|
|
58
|
+
r m_l
|
|
125
59
|
```
|
|
126
60
|
|
|
127
61
|
## Local Installation
|