LC Study Flashcards

1
Q
  1. Word Break
A

to get runtime complexity, count non-leaf nodes similar to decode ways, easier tho runtime recursion brute-force: 2^n. with memo: O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Maximum Product Subarray
A

holy fuck… i got

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Set Matrix Zeroes
A

look at submission

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Find K Closest Elements
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

237 Delete Node in a Linked List

A

have to set the next to null, if you want to remove a node. “node = null” does not work bc “node” is just a var and doesn’t alter the actual object, ~duh~. Could have used only two lines and no loop… silly boy..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Path Sum
A

DEFINITION OF ROOT-LEAF. IF THERE EXISTS ANOTHER CHILD, IT IS NOT A LEAF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Permutation in String
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Task Scheduler
A

2 diff ways with pri queue Do the calculation way

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Combination Sum
A

-best way to find how to get to target

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Binary Tree Level Order Traversal
A

bfs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Sort List
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Maximum Binary Tree
A

difficult

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. K Closest Points to Origin
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. The Skyline Problem
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. House Robber II
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. Sort Characters By Frequency
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  1. Binary Search Tree Iterator
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. Merge Intervals
A

interesting, reference the result array to make decisions and update, idk nothing to say

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. Decode Ways
A

the zero case is absolute asshole not dealing with this,….. you need to have the index represent the length or you will kys aids

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  1. Alien Dictionary
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  1. Intersection of Two Arrays
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
  1. Fizz Buzz
A

e

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  1. Reverse Nodes in k-Group
A

Use ‘nxt’ for next node name!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
  1. Clone Graph
A

submitted: both dfs and bfs solutions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
953. Verifying an Alien Dictionary
e
26
472. Concatenated Words
e
27
1192. Critical Connections in a Network
e
28
3. Longest Substring Without Repeating Characters
sliding window try optimized version heuehuehue
29
20. Valid Parentheses
wrong data structure, hubris thought i remembered soln, didn't check given test cases against my soln ;/
30
141. Linked List Cycle
Object equivalencies! use "==" and it will check if its the same object Make it nice, easier to just have more null checks than to do something fancy.
31
287. Find the Duplicate Number
constraints are for hard question
32
572. Subtree of Another Tree
e
33
101 Symmetric Tree
e
34
79. Word Search
dfs, not looking at already used letters just have dfs go to all neighbors, and have a general check for if it is correct char or out of bounds
35
83. Remove Duplicates from Sorted List
e
36
232. Implement Queue using Stacks
e
37
14. Longest Common Prefix
edge case of single element. Think of these things pls vertical scanning fastest, do it next time
38
131. Palindrome Partitioning
2 parts: longest palindorme dp array and then backtracking with partitions
39
297. Serialize and Deserialize Binary Tree
Do iterative, learned iterator
40
30. Substring with Concatenation of All Words
see sliding window notes
41
494. Target Sum
dynamic programming good problem, indexing
42
283. Move Zeros
e
43
502. IPO
e
44
124. Binary Tree Maximum Path Sum
e
45
498. Diagonal Traverse
e
46
937. Reorder Data in Log Files
e
47
29. Divide Two Integers
e
48
239. Sliding Window Maximum
e
49
55. Jump Game
simple soln
50
5 Longest Palindromic
rly good and hard, 2 methods, DP and expand from middle I did a shitty implementation of DP, try expand from middle Update: actually not so shitty after all, looks good for DP
51
986. Interval List Intersections
The interval with the shortest end point for sure doesn't have any further overlap in the array. The one with shortest start point might very well have more overlap...
52
186. Reverse Words in a String II
e
53
121 Best time to buy and sell stock 1
I got it right but I needed to increment at the end. I used a roundabout whileloop way, but should use the more efficient forloop one-pass
54
406. Queue Reconstruction by Height
insert() behavior important
55
127. Word Ladder
e
56
242 Valid Anagram
sorting is actually longer than mapping to array sorting nlogn
57
378. Kth Smallest Element in a Sorted Matrix
heap and binary search
58
341. Flatten Nested List Iterator
didnt understand q, DO AGAIN
59
588. Design In-Memory File System
e
60
373. Find K Pairs with Smallest Sums
e
61
662. Maximum Width of Binary Tree
recursive and iterative
62
938. Range Sum of BST
e
63
1268. Search Suggestions System
e
64
310. Minimum Height Trees
e
65
11 Container with Most Water
traverse width dimension
66
171. Excel Sheet Column Number
understand the problem better
67
54. Spiral Matrix
main learning: just check if len(res) is less than number of elements in matrix every time look at most recent submission
68
215. Kth Largest Element in an Array
adding, removing to priorityqueue/heap/bst is lg(n) T(n) = T(n/2) + (n-1) =\> O(n) T(n) = T(n/2) =\> O(logn) (binary search) Tags: quicksort partition
69
767. Reorganize String
e
70
21 Merge Sorted Lists
didn't assume it was ordered, use recursion. sexy solution.
71
311. Sparse Matrix Multiplication
e
72
103. Binary Tree Zigzag Level Order Traversal
Got bfs real good, DO DFS, it's pretty cool 4/17: EDIT: Beautiful most recent solution with deq. FINAL ITERATIVE, Next do recursive.
73
78 Subsets
2 neat ways of solving: Super simple and sleek python contruction second is backtracking, don't duplicate lists.
74
151. Reverse Words in a String
e
75
19 Remove Nth Node
Mine is good, look at article it shows using dummy for head which is useful soln to removing head edge case
76
338. Counting Bits
crazy, dp soln w/ pattern detecting (overlap subproblem) and really neat dp with odd/even soln
77
480. Sliding Window Median
e
78
208. Implement Trie (Prefix Tree)
e
79
322. Coin Change
KNOW RUNTIME, bottom up and top down stuff.
80
1249. Minimum Remove to Make Valid Parentheses
e
81
538. Convert BST to Greater Tree
There is a way to transfer info back up a tree, much harder tho, try global variable solution first and then discuss that way. Morris traversal is interesting
82
987. Vertical Order Traversal of a Binary Tree
e
83
138. Copy List with Random Pointer
e
84
2. Add Two Numbers
Get the implementation completely down. added new category :)
85
344. Reverse String
e
86
217 Contains Dup
I used sorting solution. I thought would be faster because nlogn + n = nlogn, and worst case for hashtable insert (hashset) is O(n), so I thought that would be O(n^2), but solution says it is only O(1).
87
252. Meeting Rooms
e
88
67. Add Binary
e
89
348. Design Tic-Tac-Toe
e
90
158. Read N Characters Given Read4 II - Call multiple times
1. Ez python way, 2. other java/c++ way with array buffer.
91
680. Valid Palindrome II
e
92
340. Longest Substring with At Most K Distinct Characters
DO THE FOLLOWUP IN DISCUSSIONS. UNDERSTAND OPTIMIZED! update: the ordered dictionary is for the follow-up: what if input is as a stream? ans: you need to store the leftmost character's position... just look at soln article!
93
128. Longest Consecutive Sequence
e
94
470. Implement Rand10() Using Rand7()
e
95
172 Trailing Zeros
math
96
759. Employee Free Time
Do K-Way Merge Idea when you get to that lesson :)
97
271. Encode and Decode Strings
e
98
69. sqrt()
O(sqrt(x)) solution not wrong, just make sure to check for overflow (i \<= x / i) binary search solution practice (many ways to do bisearch)
99
557. Reverse Words in a String III
e
100
65. Valid Number
e
101
630. Course Schedule III
e
102
895. Maximum Frequency Stack
e
103
1239. Maximum Length of a Concatenated String with Unique Characters
e
104
62. Unique Paths
memo, weird matrix layout, try to understand and do yourself dp iteration, look at most recent submission
105
704. Binary Search
e
106
1152. Analyze User Website Visit Pattern
e
107
117. Populating Next Right Pointers in Each Node II
I used solution article, keep with sachin my boi, other discussion solutions are gay as fuck
108
98. Validate Binary Search Tree
try iteration(stack), and in-order next time too
109
543. Diameter of Binary Tree
e
110
207. Course Schedule
cycle detection method and topological sort \*\*\*huge revisit, lot to learn from this one. didn't really do cycle detection one but seems fun
111
284. Peeking Iterator
e
112
721. Accounts Merge
e
113
17. Letter Combinations of a Phone Number
e
114
694. Number of Distinct Islands
e
115
384. Shuffle an Array
another design similar to right above!! woooooooo!!!!!!! love it !!!! tyes1!!!!!!!! awassome!!!
116
1185. Day of the Week
e
117
57. Insert Interval
dont waste time implementing a wrong algo... duh
118
647. Palindromic Substrings
dp and expand solutions
119
64. Minimum Path Sum
MAKE SPACE EFFICIENT sick O(n) space soln
120
38 Count and say
Integer.toString() takes a long time, changed it just to result.append(times) where "times" is an integer \*able to append int to StringBuilder
121
398. Random Pick Index
e
122
35. Search Insert Position
also a handle for dups
123
468. Validate IP Address
e
124
169. Majority Element
quick ans
125
535. Encode and Decode TinyURL
e
126
66 Plus One
cool
127
204. Count Primes
ancient greek algorithm sieve of arasmuth cool (in hints)
128
136. Single Number
e
129
977. Squares of a Sorted Array
e
130
100. Same Tree
LEARNED: DFS iteratively uses stack. BFS iteratively uses a queue submitted: most recent is BFS using queue solution, next is recursion update: the dfs w/ stack is preorder
131
96. Unique Binary Search Trees
do dp.
132
437. Path Sum III
insane solution, got brute recursion tho, caching solution is muy dificil
133
785. Is Graph Bipartite?
e
134
819. Most Common Word
e
135
200. Number of Islands
e
136
190. Reverse Bits
unsigned left shift doesn't exist, does the same as \<
137
909. Snakes and Ladders
e
138
1. Two Sum
find the edge :/ same num used twice, don't get too confident bruh one-pass available
139
226. Invert Binary Tree
bfs, dfs, recursive, iterative
140
94. Binary Tree Inorder Traversal
try without altering initial data structure, I forgot to reset the node's left to null so it infinitely looped
141
88. Merge sorted Array
hit it from the baackkkk most recent submission the soln I like
142
394. Decode String
like flatten nest list, kinda unique stack question, hopefully anotherone like it somewhere
143
47. Permutations II
good, one extra step was to iterate on the counts, not the nums to not look at double.
144
116. Populating Next Right Pointers in Each Node
DO AGAIN
145
125. Valid Palindrome
skip completely alphanumeric, also isLetterOrDigit() try without extra space next time!
146
10. Regular Expression Matching
e
147
636. Exclusive Time of Functions
e
148
692. Top K Frequent Words
e
149
528. Random Pick with Weight
e
150
74. Search a 2D Matrix
cool cool cool cool
151
153. Find Minimum in Rotated Sorted Array
good to learn bisearch inside and out, so many edge cases. l \< r if you want to break and return outside of loop use r = mid in order to close in on one specific target from two arrays, otherwise you lose a potential number jesus binary search is hard, keep trying and cross-comparing different q's
152
301. Remove Invalid Parentheses
e
153
545. Boundary of Binary Tree
e
154
111. Minimum Depth of Binary Tree
iterative BFS (could attach depth to node w/ a tuple. I like generalized global mindepth tho its more like level order), Try all others versions (DFS, recursive).
155
460. LFU Cache
e
156
452. Minimum Number of Arrows to Burst Balloons
not easy in the slightest, greedy
157
198 House Robber
practice the iterative version as well. Maybe take a crack at the 2 variable one
158
994. Rotting Oranges
e
159
33. Search in Rotated Sorted Array
two ways, 1: look if low and mid are on the same side, then do checks based on that (its either increasing from low to mid, or increasing from mid to high) 2: look at pivot to determine if mid and target are on the same side, then do checks based on that.
160
114. Flatten Binary Tree to Linked List
some crazy ass prev shit LOOK OVER AGAIN FOR SURE
161
744. Find Smallest Letter Greater Than Target
e
162
282. Expression Add Operators
e
163
122 Buy sell stock
I remembered somehow, understand the peak-valley deal
164
118 Pascals Triangle
look at fucking return types, had to change whole thing
165
309. Best Time to Buy and Sell Stock with Cooldown
state machine, iterpreting into dp code, optimizing. very good, look at generalization article too
166
26. Remove Duplicates from Sorted Array
Good job altering from original plan to most efficient possible algo! (Beats 100%)
167
140. Word Break II
e
168
212. Word Search II
DO OPTIMIZATION: its in the solution code in a comment.
169
199. Binary Tree Right Side View
DO RECURSION METHOD (reverse pre-order) I got the level order bfs queue version.
170
46. Permutations
list concatenation is O(n). list slicing is O(n). Use hashset to be faster than checking if it exists in a list. Time complexity would be O(n!\*n) with list checking. O(n!) w/ set space is O(n!) bc of res.
171
160. Intersection of two Linked Lists
hashset soln if not find other one can have stop condition be while(nodeA != nodeB) bc they will both be null at some point
172
261. Graph Valid Tree
e
173
162. Find Peak Element
there are some sneaky things with bisearch that ppl solns did, mine is easy to understand but has more lines, later attempt to implement those sneaky things if you see them a lot more? also RECURSIVE VERSION
174
637. Average of Levels in Binary Tree
Iterative BFS done. Do recursive/DFS
175
42. Trapping Rain Water
Key Takeaway: even on LC Hard, the fundemental idea you need in order to solve the problem is not too outrageous: min(maxleft, maxright) - curheight basically, don't think its not possible NEXT: UNDERSTAND STACK SOLUTION!!
176
289. Game of Life
implement it
177
438. Find All Anagrams in a String
Sliding window, plan on memorizing this shit real good
178
380. Insert Delete GetRandom O(1)
get it or u dont, hint: -swap-
179
15 3Sum
super annoying implementation, needing to protect agianst dups just gross
180
49. Group Anagrams
learned defaultdict, using tuples
181
16. 3Sum Closest
Once find target, return immediately :)
182
852. Peak Index in a Mountain Array
peak finding
183
268 Missing Number
I thought about doing the sum thing ;0 ;0 ;0 should have thought more ://
184
23. Merge k Sorted Lists
e
185
191 Nubmer of 1 bits
nice
186
270. Closest Binary Search Tree Value
e
187
7. Reverse Integer
Negative modulus Overflow cycles hella, cant rely on just being less than or greater than previous number. must check if not equal to previous number
188
435. Non-overlapping Intervals
I did sort by first element, best is sort by second
189
203. Remove Linked List Elements
e
190
134. Gas Station
e
191
273. Integer to English Words
e
192
323. Number of Connected Components in an Undirected Graph
e
193
108 Convert Sorted Array to BST
edge case len = 0
194
48 Rotate Image
ctci
195
211. Add and Search Word - Data structure design
e
196
235. Lowest Common Ancestor of a Binary Search Tree
try again, iterative too
197
143. Reorder List
neat most recent submission
198
105. Construct Binary Tree from Preorder and Inorder Traversal
bisearch on tree kinda Do java soln to avoid splice time creating new lists from that python guy
199
442. Find All Duplicates in an Array
e
200
61. Rotate List
nice
201
326 Power of three
smokeout
202
225. Implement Stack using Queues
e
203
81. Search in Rotated Sorted Array II
e
204
337. House Robber III
GENERALLY PASS UP INFORMATION. I tried passing down info, and not good recursive practice. Try to say, given the info of node below, what do I do now? Instead of passing info about current problem down to below problem, actually its just top-down vs bottom-up. ACTUALLY IDK, KEEP A LOOK OUT FOR THIS AND COME BACK. SEE IF OPINION CHANGES
205
93. Restore IP Addresses
e
206
210. Course Schedule II
e
207
99. Recover Binary Search Tree
e
208
454. 4Sum II
pretty simple actually
209
560. Subarray Sum Equals K
looks like sliding window, but actually presum + 2 sum very cool stuff
210
146. LRU Cache
e
211
445. Add Two Numbers II
e
212
104. Max Depth of BST
e
213
957. Prison Cells After N Days
e
214
234 Palindrome Linked List
really good, optimization and clean code should be attempted next time!! I like my solution the best actually, most recent submission has cleaner for-loops than first 2nd attemp soln
215
206 Reverse Linked List
try recursive next time,also only need 2 temps to start
216
1044. Longest Duplicate Substring
e
217
387 First unique character in string
I traversed wrong array for second loop.... dumb boy..
218
461. Hamming Distance
many ways to do
219
417. Pacific Atlantic Water Flow
try bfs, direction thing too
220
113. Path Sum II
backtracking aspect. Really good point on BFS vs DFS here in solution article. Take note of this Time complexity
221
328. Odd Even Linked List
got it
222
24. Swap Nodes in Pairs
recursive soln next
223
416. Partition Equal Subset Sum
0/1 knapsack
224
230 Kth Smallest Element
inorder traverse ez, python global vars n shi try iteration? DO FOLLOW-UP SIMILAR TO LRU CACHE
225
76. Minimum Window Substring
time space linear
226
443. String Compression
e
227
763. Partition Labels
e
228
896. Monotonic Array
e
229
523. Continuous Subarray Sum
e
230
424. Longest Repeating Character Replacement
Can get O(n) by never shrinking the window
231
53 Maximum Subarray
memorize algo
232
863. All Nodes Distance K in Binary Tree
Build a graph out of the tree, then BFS. Try other solution w/o creating graph
233
28. Implement Str()str()
only traverse haystack.length() - needle.length()+1 use i + j instead of h and use 2nd for loop for ease
234
159. Longest Substring with At Most Two Distinct Characters
NOTE IMPORTANT\*\*\*\*: DO OPTIMIZED SOLUTION.
235
642. Design Search Autocomplete System
e
236
295. Find Median from Data Stream
BST solution, list solution, 2 heaps solution
237
126. Word Ladder II
e
238
202 Happy Number
Gucci (Edit months later: No. u are not gucci u idiot ahaha)
239
581. Shortest Unsorted Continuous Subarray
hard array...
240
300. Longest Increasing Subsequence
dp, also nlogn unnecessary tho
241
428. Serialize and Deserialize N-ary Tree
e
242
347. Top K Frequent Elements
ATTENTION: NOW SWITCHING TO PYTHON LOLOLOLOL bucket sort
243
142. Linked List Cycle II
e
244
844. Backspace String Compare
e
245
240. Search a 2D Matrix II
implement it
246
75. Sort Colors
3 ptr basically or 2 ptr + iteration Tags: quicksort partition
247
876. Middle of the Linked List
e
248
713. Subarray Product Less Than K
e
249
279. Perfect Squares
bfs and dp, implement it
250
253. Meeting Rooms II
e
251
31. Next Permutation
e
252
22. Generate Parentheses
Errors having to do both with understanding stringbuilder class: initialize with string "(" NOT '(' Understand why deleteChar(i) after each append :) CONDENSE THAT SHIT (I like my soln, try to condense it continuing using SB, with the given solution's if statements) most recent submission is hype
253
236. Lowest Common Ancestor of a Binary Tree
Do iterative
254
510. Inorder Successor in BST II
e
255
371. Sum of Two Integers
e
256
1167. Minimum Cost to Connect Sticks
e
257
70. Climbing Stairs
dp, fibonnaci nice
258
448. Find All Numbers Disappeared in an Array
negation shit stupid
259
238 Product of Array Except Self
try in constance time follow up, not very different from linear time
260
350 Intersections of two arrays II
e
261
334. Increasing Triplet Subsequence
reducing to 3's, means using that info to reduce time. Like sorting color too.
262
670. Maximum Swap
e
263
415. Add Strings
e
264
1060. Missing Element in Sorted Array
e
265
92. Reverse Linked List II
I like my soln the best, most intuitive
266
155. Min Stack
useful prob
267
189. Rotate Array
tried and failed miserably to do in place Reason I failed: checking if the values were equivalent rather than looking at the indexes. Soln: if reach same starting idx, just look at the next idx and go through that loop, THATs the stopping condition, when n swaps! got the extra space soln tho
268
689. Maximum Sum of 3 Non-Overlapping Subarrays
e
269
107. Binary Tree Level Order Traversal II
Do Recursive next
270
13. Roman to Integer
store vals better (hash or array), add all accross and then subtract if necessary, ask if it will always be valid! then, dont need each case
271
150. Evaluate Reverse Polish Notation
e