-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathleet.html
99 lines (85 loc) · 3.45 KB
/
leet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<head>
<title>
leontrolski - interview patterns
</title>
<style>
body {margin: 5% auto; background: #fff7f7; color: #444444; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.8; max-width: 63%;}
@media screen and (max-width: 800px) {body {font-size: 14px; line-height: 1.4; max-width: 90%;}}
pre {width: 100%; border-top: 3px solid gray; border-bottom: 3px solid gray;}
a {border-bottom: 1px solid #444444; color: #444444; text-decoration: none; text-shadow: 0 1px 0 #ffffff; }
a:hover {border-bottom: 0;}
.inline {background: #b3b2b226; padding-left: 0.3em; padding-right: 0.3em; white-space: nowrap;}
blockquote {font-style: italic;color:black;background-color:#f2f2f2;padding:2em;}
details {border-bottom:solid 5px gray;}
</style>
<link href="https://unpkg.com/[email protected]/themes/prism-vs.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/components/prism-core.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/plugins/autoloader/prism-autoloader.min.js">
</script>
</head>
<body>
<a href="index.html">
<img src="pic.png" style="height:2em">
⇦
</a>
<p><i>2022-03-31</i></p>
<h1>
Interview patterns in Python
</h1>
<p>
Not necessarily fastest, but hopefully neatest. Recursive problems can be generically converted to while loops to circumvent recursion limit.
</p>
<details id="top">
<summary>
Variable naming conventions.
</summary>
<pre class="language-python"><code>x y z # values
i j k # corresponding indices
xs ys zs # lists of values
t # a target to aim for
w # the path to something
a # something we accumulate
f # a function used for recursion
n # a node in a tree or graph
b # a place to mark things we've already done
l # an input list
s # an input string
p # an input pattern
.v .l .r .n # the value, left, right, next of a node in a tree
.._prev # the previous of something
.._next # the next of something
.._new # a new version of something</code>
</pre>
</details>
<details>
<summary>
Imports required to run the examples.
</summary>
<pre class="language-python"><code>from __future__ import annotations
from collections import defaultdict
from dataclasses import dataclass
from functools import cache # a lot of the `f(...)` below can be memoized
from itertools import count
from types import SimpleNamespace</code>
</pre>
</details>
<br>
<div id="root">
</div>
<style>
.tag{margin:0.25rem 0.5rem 0.25rem 0;padding:0.25rem 0.5rem 0.25rem 0.5rem;}
.tag-selected{font-weight:bold;}
.problem{margin-top:4rem;}
.no-border{border:none;}
.description{padding-left:1rem;}
.question{padding-bottom:0.5rem;}
</style>
<script src="33-line-react.js">
</script>
<script src="leet.js">
</script>
</body>
</html>