@scurrlin/stencil 1.5.2 → 1.5.3

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.
Files changed (2) hide show
  1. package/README.md +95 -27
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -14,46 +14,114 @@ 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 29 "Divide Two Integers":
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 30 "Substring with Concatenation of All Words":
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
+
24
27
  class Solution:
25
- def divide(self, dividend: int, divisor: int) -> int:
26
- if dividend == -2 ** 31 and divisor == -1:
27
- return 2 ** 31 - 1
28
-
29
- sign = -1 if (dividend < 0)^(divisor < 0) else 1
30
- quotient = 0
31
- dividend = abs(dividend)
32
- divisor = abs(divisor)
33
- for i in range(31, -1, -1):
34
- if (divisor << i) <= dividend:
35
- dividend -= (divisor << i)
36
- quotient |= (1 << i)
37
- return sign * quotient
28
+ def findSubstring(self, s: str, words: List[str]) -> List[int]:
29
+ if not s or not words:
30
+ return []
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 = []
42
+
43
+ for start_offset in range(word_len):
44
+ left = start_offset
45
+ matched_words = 0
46
+ seen_count = defaultdict(int)
47
+ for right in range(start_offset, len(s), word_len):
48
+ current_word = s[right : right + word_len]
49
+ if current_word in word_count:
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
67
+ else:
68
+ seen_count.clear()
69
+ matched_words = 0
70
+ left = right + word_len
71
+ return result
38
72
  ```
39
73
 
40
74
  Solution with Stencil
41
75
 
42
76
  ```python
77
+ f c i d
78
+ f t i L
79
+
43
80
  c S:
44
- d d(s, d: i, d: i) -> i:
45
- i d == -2 ** 3 a d == -1:
46
- r 2 ** 3 - 1
47
-
48
- s = -1 i (d < 0)^(d < 0) e 1
49
- q = 0
50
- d = a(d)
51
- d = a(d)
52
- f i i r(3, -1, -1):
53
- i (d << i) <= d:
54
- d -= (d << i)
55
- q |= (1 << i)
56
- r s * q
81
+ d f(s, s: s, w: L[s]) -> L[i]:
82
+ i n s o n w:
83
+ r []
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 = []
95
+
96
+ f s_o i r(w_l):
97
+ l = s_o
98
+ m_w = 0
99
+ s_c = d(i)
100
+ f r i r(s_o, l(s), w_l):
101
+ c_w = s[r : r + w_l]
102
+ i c_w i w_c:
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
120
+ e:
121
+ s_c.c()
122
+ m_w = 0
123
+ l = r + w_l
124
+ r r
57
125
  ```
58
126
 
59
127
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "A memorization tool that strips code down to first letters and punctuation only.",
5
5
  "main": "src/index.js",
6
6
  "bin": {