-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint-all.html
More file actions
543 lines (501 loc) · 31.1 KB
/
print-all.html
File metadata and controls
543 lines (501 loc) · 31.1 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LeetCode Flashcards - Print Ready</title>
<style>
@page {
size: A4;
margin: 0.3cm;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Courier New', monospace;
font-size: 9pt;
line-height: 1.3;
}
.flashcard {
width: 19cm; /* Slightly narrower for better centering */
height: auto; /* Height adjusts to content */
min-height: 12cm; /* Minimum height */
border: 3px solid #333;
page-break-after: always;
padding: 1cm; /* Even padding on all sides */
position: relative;
background: white;
margin: 1cm auto; /* Center horizontally and vertically */
box-sizing: border-box;
}
.flashcard.front {
background: #f8f9fa;
}
.flashcard.back {
background: #e9ecef;
}
.flashcard.easy { border-color: #28a745; border-width: 3px; }
.flashcard.medium { border-color: #ffc107; border-width: 3px; }
.flashcard.hard { border-color: #dc3545; border-width: 3px; }
.header {
font-weight: bold;
font-size: 10pt;
padding-bottom: 0.1in;
border-bottom: 1px solid #666;
margin-bottom: 0.15in;
}
.content {
font-size: 8pt;
white-space: pre-wrap;
}
.hints, .solution {
margin-top: 0.15in;
padding-top: 0.15in;
border-top: 1px dashed #999;
}
.complexity {
position: absolute;
bottom: 0.25in;
left: 0.25in;
right: 0.25in;
padding-top: 0.1in;
border-top: 1px solid #999;
font-size: 8pt;
font-weight: bold;
}
code {
background: #f4f4f4;
padding: 0.05in;
font-size: 7pt;
}
@media screen {
body {
background: #ddd;
padding: 20px;
}
.flashcard {
margin: 20px auto;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
border-radius: 4px;
}
}
@media print {
body {
background: white;
margin: 0;
padding: 0;
}
.flashcard {
margin: 1cm auto; /* Keep centering when printing */
box-shadow: none;
}
@page {
margin: 0.3cm;
}
}
@media print {
body {
background: white;
}
.no-print {
display: none;
}
}
pre {
white-space: pre;
font-family: 'Courier New', monospace;
font-size: 10pt; /* Bigger font since card is bigger */
line-height: 1.4;
margin: 0 auto;
padding: 0;
display: table; /* Makes pre element shrink-wrap and center */
}
</style>
</head>
<body>
<div class="no-print" style="text-align: center; padding: 20px; background: white; margin-bottom: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
<h1>🎴 LeetCode Flashcards - Print Ready</h1>
<p style="margin: 10px 0;"><strong>Total Problems:</strong> 9 problems × 2 cards = 18 total cards</p>
<p style="margin: 10px 0;"><strong>Print Instructions:</strong></p>
<ol style="text-align: left; display: inline-block; margin: 10px auto;">
<li>File → Print (⌘P / Ctrl+P)</li>
<li>✅ Check "Print background graphics"</li>
<li>Select printer or "Save as PDF"</li>
<li>Print double-sided for front/back (optional)</li>
<li>Cut along borders (4×6 inches each)</li>
</ol>
<p style="margin-top: 15px; color: #666;">💡 Tip: Print on cardstock for durability!</p>
</div>
<div class="flashcard front easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #1 Two Sum 🟢 Easy │
├──────────────────────────────────────────────────────┤
│ │
│ Given an array of integers nums and an integer │
│ target, return indices of the two numbers such │
│ that they add up to target. You may assume that │
│ each ... Ex: In=[nums = [2,7,11,15], target = 9] │
│ Out=[[0,1]] │
│ │
│ │
│ 💡 HINTS: │
│ • Have we seen this element before? │
│ • What gives O(1) lookup/insert? │
│ │
│ 🎯 PATTERN: Hash Table / Array & Hashing │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #1 Two Sum - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use HashMap to store seen elements for O(1) │
│ lookup │
│ │
│ 🔢 ALGORITHM: │
│ 1. Create HashMap to store value→index │
│ 2. For each element: │
│ - Check if complement exists in map │
│ - If yes: return indices │
│ - If no: add current to map │
│ │
│ ⏱️ O(n) 💾 O(n) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #125 Valid Palindrome 🟢 Easy │
├──────────────────────────────────────────────────────┤
│ │
│ **LeetCode #125:** [Valid │
│ Palindrome](https://leetcode.com/problems/valid-pa │
│ Ex: In=[s = "A man, a plan, a canal: Panama"] │
│ Out=[true] │
│ │
│ │
│ │
│ 💡 HINTS: │
│ • Check symmetry without reversing? │
│ • What if special chars scattered? │
│ │
│ 🎯 PATTERN: Two Pointers │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #125 Valid Palindrome - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use two pointers from edges, skip │
│ non-alphanumeric independently with bounds │
│ │
│ 🔢 ALGORITHM: │
│ 1. Initialize `left = 0`, `right = length - 1` │
│ 2. Skip non-alphanumeric from left (with `left < r │
│ 3. Skip non-alphanumeric from right (with `left < │
│ 4. Compare `toLowerCase(s[left])` with `toLowerCas │
│ 5. Move both pointers inward; return false on mism │
│ │
│ ⏱️ O(n) 💾 O(1) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #128 Longest Consecutive Sequence 🟡 Medium │
├──────────────────────────────────────────────────────┤
│ │
│ Given an unsorted array of integers nums, return │
│ the length of the longest consecutive elements │
│ sequence. You must write an algorithm that runs │
│ in ... Ex: In=[nums = [100,4,200,1,3,2]] Out=[4] │
│ │
│ │
│ │
│ 💡 HINTS: │
│ • How to check if num-1 or num+1 exist quickly? │
│ • How to avoid counting same sequence twice? │
│ │
│ 🎯 PATTERN: Hash Table / Array & Hashing │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #128 Longest Consecutive Seque - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Only count from sequence starts (where num-1 │
│ doesn't exist). Iterate over HashSet, not array! │
│ │
│ 🔢 ALGORITHM: │
│ 1. Build HashSet for O(1) lookups │
│ 2. Iterate over HashSet (not array!) │
│ 3. If num-1 doesn't exist: sequence start │
│ 4. Count consecutive: num→num+1→num+2... │
│ 5. Track max length │
│ │
│ ⏱️ O(n) 💾 O(n) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #217 Contains Duplicate 🟢 Easy │
├──────────────────────────────────────────────────────┤
│ │
│ Given an integer array nums, return true if any │
│ value appears at least twice in the array, and │
│ return false if every element is distinct. Ex: │
│ In=[nums = [1,2,3,1]] Out=[true] │
│ │
│ │
│ │
│ 💡 HINTS: │
│ • Have we seen this element before? │
│ • What data structure gives O(1) lookup? │
│ │
│ 🎯 PATTERN: Hash Table / Array & Hashing │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #217 Contains Duplicate - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use HashSet to track seen elements - if we see │
│ an element that's already in the set, we found a │
│ │
│ 🔢 ALGORITHM: │
│ 1. Create empty HashSet │
│ 2. For each number in array │
│ 3. If number exists in set: return true │
│ 4. Add number to set │
│ 5. Return false (no duplicates found) │
│ │
│ ⏱️ O(n) 💾 O(n) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #238 Product of Array Except Self 🟡 Medium │
├──────────────────────────────────────────────────────┤
│ │
│ Given an integer array nums, return an array │
│ answer such that answer[i] is equal to the │
│ product of all the elements of nums except │
│ nums[i]. The pro... Ex: In=[nums = [1,2,3,4]] │
│ Out=[[24,12,8,6]] │
│ │
│ │
│ 💡 HINTS: │
│ • Can we use prefix and suffix products? │
│ • How to avoid division? │
│ │
│ 🎯 PATTERN: Array Manipulation / Prefix-Suffix │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #238 Product of Array Except S - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use two passes - prefix products left→right, │
│ then multiply by suffix products right→left, │
│ │
│ 🔢 ALGORITHM: │
│ 1. Create result array │
│ 2. Forward pass: Store prefix products in result │
│ 3. Backward pass: Multiply by suffix products │
│ 4. Each result[i] = (product of all left) × (produ │
│ 5. Return result array │
│ │
│ ⏱️ O(n) 💾 O(1) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #242 Valid Anagram 🟢 Easy │
├──────────────────────────────────────────────────────┤
│ │
│ Given two strings s and t, return true if t is │
│ an anagram of s, and false otherwise. An Anagram │
│ is a word or phrase formed by rearranging the │
│ lette... Ex: In=[s = "anagram", t = "nagaram"] │
│ Out=[true] │
│ │
│ │
│ 💡 HINTS: │
│ • Do both strings need same character frequencies? │
│ • Can sorting help? │
│ │
│ 🎯 PATTERN: Hash Table / Array & Hashing │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back easy">
<pre>┌──────────────────────────────────────────────────────┐
│ #242 Valid Anagram - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Count character frequencies - two strings are │
│ anagrams if they have identical character counts │
│ │
│ 🔢 ALGORITHM: │
│ 1. Check if lengths differ (early return false) │
│ 2. Count frequency of each char in both strings │
│ 3. Compare frequency maps or arrays │
│ 4. Return true if identical, false otherwise │
│ │
│ │
│ ⏱️ O(n) 💾 O(1) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #271 Encode and Decode Strings 🟡 Medium │
├──────────────────────────────────────────────────────┤
│ │
│ Design an algorithm to encode a list of strings │
│ to a string. The encoded string is then sent │
│ over the network and is decoded back to the │
│ original l... Ex: │
│ In=[["lint","code","love","you"]] │
│ Out=[["lint","code","love","you"]] │
│ │
│ 💡 HINTS: │
│ • Can delimiters appear in the data itself? │
│ • How can length information help avoid collisions │
│ │
│ 🎯 PATTERN: String Manipulation │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #271 Encode and Decode Strings - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use length#string format - once we know length, │
│ we can safely extract exact chars (delimiters │
│ │
│ 🔢 ALGORITHM: │
│ 1. Encode: append length + "#" + string │
│ 2. Decode: read length, skip "#", extract chars │
│ 3. Reset pointers: j = i after each extraction │
│ │
│ │
│ │
│ ⏱️ O(n) 💾 O(n) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #347 Top K Frequent Elements 🟡 Medium │
├──────────────────────────────────────────────────────┤
│ │
│ Given an integer array nums and an integer k, │
│ return the k most frequent elements. You may │
│ return the answer in any order. Ex: In=[nums = │
│ [1,1,1,2,2,3], k = 2] Out=[[1,2]] │
│ │
│ │
│ │
│ 💡 HINTS: │
│ • Need all sorted or just top k? │
│ • Can frequency be used as index? │
│ │
│ 🎯 PATTERN: Top K Elements │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #347 Top K Frequent Elements - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use frequency as array index for O(n) bucket │
│ sort │
│ │
│ 🔢 ALGORITHM: │
│ 1. Count frequencies with HashMap │
│ 2. Create buckets[n+1] or use heap │
│ 3. Place elements in bucket[frequency] │
│ 4. Traverse high→low, collect k items │
│ │
│ │
│ ⏱️ O(n) 💾 O(n) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<div class="flashcard front medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #49 Group Anagrams 🟡 Medium │
├──────────────────────────────────────────────────────┤
│ │
│ Given an array of strings strs, group the │
│ anagrams together. You can return the answer in │
│ any order. An Anagram is a word or phrase formed │
│ by rearr... Ex: In=[strs = │
│ ["eat","tea","tan","ate","nat","bat"]] │
│ Out=[[["bat"],["nat","tan"],["ate","eat","tea"]]] │
│ │
│ 💡 HINTS: │
│ • What do anagrams have in common when sorted? │
│ • Can sorted string be a key? │
│ │
│ 🎯 PATTERN: Hash Table / Array & Hashing │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
<!-- BACK card -->
<div class="flashcard back medium">
<pre>┌──────────────────────────────────────────────────────┐
│ #49 Group Anagrams - SOLUTION │
├──────────────────────────────────────────────────────┤
│ │
│ 💡 KEY INSIGHT: │
│ Use sorted string as HashMap key - all anagrams │
│ will have the same sorted representation and map │
│ │
│ 🔢 ALGORITHM: │
│ 1. Create HashMap<String, List<String>> │
│ 2. For each string: sort it │
│ 3. Use sorted string as key │
│ 4. Add original string to list at that key │
│ 5. Return all values from HashMap │
│ │
│ ⏱️ O(n × m) 💾 O(n × m) │
│ │
└──────────────────────────────────────────────────────┘</pre>
</div>
</body></html>