@scurrlin/stencil 1.35.3 → 1.35.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.
Files changed (2) hide show
  1. package/README.md +65 -55
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,72 +16,82 @@ Whether you are studying for technical interviews, or just starting your coding
16
16
 
17
17
  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.
18
18
 
19
- 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 378 "Kth Smallest Element in a Sorted Matrix":
19
+ 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 381 "Insert Delete GetRandom O(1) - Duplicates allowed":
20
20
 
21
21
  ## Example
22
22
 
23
23
  Solution
24
24
 
25
25
  ```python
26
- class Solution:
27
- def countElements(self, matrix, target):
28
- n = len(matrix)
29
- row, col, count = n - 1, 0, 0
30
-
31
- while row >= 0 and col < n:
32
- if matrix[row][col] <= target:
33
- count += (row + 1)
34
- col += 1
35
- else:
36
- row -= 1
37
- return count
38
-
39
- def kthSmallest(self, matrix, k: int) -> int:
40
- n = len(matrix)
41
- low, high = matrix[0][0], matrix[-1][-1]
42
- ans = 0
43
-
44
- while low <= high:
45
- mid = (low + high)//2
46
- count = self.countElements(matrix, mid)
47
- if count >= k:
48
- ans = mid
49
- high = mid - 1
50
- else:
51
- low = mid + 1
52
- return ans
26
+ class RandomizedCollection:
27
+
28
+ def __init__(self):
29
+ self.mp = defaultdict(set)
30
+ self.items = []
31
+
32
+ def insert(self, val: int) -> bool:
33
+ ret = val not in self.mp
34
+ self.mp[val].add(len(self.items))
35
+ self.items.append(val)
36
+ return ret
37
+
38
+ def remove(self, val: int) -> bool:
39
+ if val not in self.mp:
40
+ return False
41
+
42
+ i = self.mp[val].pop()
43
+
44
+ if len(self.mp[val]) == 0:
45
+ del self.mp[val]
46
+
47
+ if i != (len(self.items) - 1):
48
+ last_val = self.items[-1]
49
+ self.items[i] = last_val
50
+ self.mp[last_val].remove(len(self.items) - 1)
51
+ self.mp[last_val].add(i)
52
+
53
+ self.items.pop()
54
+ return True
55
+
56
+ def getRandom(self) -> int:
57
+ return random.choice(self.items)
53
58
  ```
54
59
 
55
60
  Solution with Stencil
56
61
 
57
62
  ```python
58
- c S:
59
- d c(s, m, t):
60
- n = l(m)
61
- r, c, c = n - 1, 0, 0
62
-
63
- w r >= 0 a c < n:
64
- i m[r][c] <= t:
65
- c += (r + 1)
66
- c += 1
67
- e:
68
- r -= 1
69
- r c
70
-
71
- d k(s, m, k: i) -> i:
72
- n = l(m)
73
- l, h = m[0][0], m[-1][-1]
74
- a = 0
75
-
76
- w l <= h:
77
- m = (l + h)//2
78
- c = s.c(m, m)
79
- i c >= k:
80
- a = m
81
- h = m - 1
82
- e:
83
- l = m + 1
84
- r a
63
+ c R:
64
+
65
+ d __i__(s):
66
+ s.m = d(s)
67
+ s.i = []
68
+
69
+ d i(s, v: i) -> b:
70
+ r = v n i s.m
71
+ s.m[v].a(l(s.i))
72
+ s.i.a(v)
73
+ r r
74
+
75
+ d r(s, v: i) -> b:
76
+ i v n i s.m:
77
+ r F
78
+
79
+ i = s.m[v].p()
80
+
81
+ i l(s.m[v]) == 0:
82
+ d s.m[v]
83
+
84
+ i i != (l(s.i) - 1):
85
+ l_v = s.i[-1]
86
+ s.i[i] = l_v
87
+ s.m[l_v].r(l(s.i) - 1)
88
+ s.m[l_v].a(i)
89
+
90
+ s.i.p()
91
+ r T
92
+
93
+ d g(s) -> i:
94
+ r r.c(s.i)
85
95
  ```
86
96
 
87
97
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.35.3",
3
+ "version": "1.35.5",
4
4
  "type": "module",
5
5
  "description": "A memorization tool that strips code down to first letters and punctuation only.",
6
6
  "main": "dist/src/index.js",