LC Study Flashcards
- Word Break
to get runtime complexity, count non-leaf nodes similar to decode ways, easier tho runtime recursion brute-force: 2^n. with memo: O(n)
- Maximum Product Subarray
holy fuck… i got
- Set Matrix Zeroes
look at submission
- Find K Closest Elements
e
237 Delete Node in a Linked List
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..
- Path Sum
DEFINITION OF ROOT-LEAF. IF THERE EXISTS ANOTHER CHILD, IT IS NOT A LEAF
- Permutation in String
e
- Task Scheduler
2 diff ways with pri queue Do the calculation way
- Combination Sum
-best way to find how to get to target
- Binary Tree Level Order Traversal
bfs
- Sort List
e
- Maximum Binary Tree
difficult
- K Closest Points to Origin
e
- The Skyline Problem
e
- House Robber II
e
- Sort Characters By Frequency
e
- Binary Search Tree Iterator
e
- Merge Intervals
interesting, reference the result array to make decisions and update, idk nothing to say
- Decode Ways
the zero case is absolute asshole not dealing with this,….. you need to have the index represent the length or you will kys aids
- Alien Dictionary
e
- Intersection of Two Arrays
e
- Fizz Buzz
e
- Reverse Nodes in k-Group
Use ‘nxt’ for next node name!
- Clone Graph
submitted: both dfs and bfs solutions
- Verifying an Alien Dictionary
e
- Concatenated Words
e
- Critical Connections in a Network
e
- Longest Substring Without Repeating Characters
sliding window try optimized version heuehuehue
- Valid Parentheses
wrong data structure, hubris thought i remembered soln, didn’t check given test cases against my soln ;/
- 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.
- Find the Duplicate Number
constraints are for hard question
- Subtree of Another Tree
e
101 Symmetric Tree
e
- 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
- Remove Duplicates from Sorted List
e
- Implement Queue using Stacks
e
- Longest Common Prefix
edge case of single element. Think of these things pls vertical scanning fastest, do it next time
- Palindrome Partitioning
2 parts: longest palindorme dp array and then backtracking with partitions
- Serialize and Deserialize Binary Tree
Do iterative, learned iterator
- Substring with Concatenation of All Words
see sliding window notes
- Target Sum
dynamic programming good problem, indexing
- Move Zeros
e
- IPO
e
- Binary Tree Maximum Path Sum
e
- Diagonal Traverse
e
- Reorder Data in Log Files
e
- Divide Two Integers
e
- Sliding Window Maximum
e
- Jump Game
simple soln
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
- 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…
- Reverse Words in a String II
e
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
- Queue Reconstruction by Height
insert() behavior important
- Word Ladder
e
242 Valid Anagram
sorting is actually longer than mapping to array sorting nlogn
- Kth Smallest Element in a Sorted Matrix
heap and binary search
- Flatten Nested List Iterator
didnt understand q, DO AGAIN
- Design In-Memory File System
e
- Find K Pairs with Smallest Sums
e
- Maximum Width of Binary Tree
recursive and iterative
- Range Sum of BST
e
- Search Suggestions System
e
- Minimum Height Trees
e
11 Container with Most Water
traverse width dimension
- Excel Sheet Column Number
understand the problem better
- Spiral Matrix
main learning: just check if len(res) is less than number of elements in matrix every time look at most recent submission
- 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
- Reorganize String
e
21 Merge Sorted Lists
didn’t assume it was ordered, use recursion. sexy solution.
- Sparse Matrix Multiplication
e
- 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.
78 Subsets
2 neat ways of solving: Super simple and sleek python contruction second is backtracking, don’t duplicate lists.
- Reverse Words in a String
e
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
- Counting Bits
crazy, dp soln w/ pattern detecting (overlap subproblem) and really neat dp with odd/even soln
- Sliding Window Median
e
- Implement Trie (Prefix Tree)
e
- Coin Change
KNOW RUNTIME, bottom up and top down stuff.
- Minimum Remove to Make Valid Parentheses
e
- 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
- Vertical Order Traversal of a Binary Tree
e
- Copy List with Random Pointer
e
- Add Two Numbers
Get the implementation completely down. added new category :)
344. Reverse String
e
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).
- Meeting Rooms
e
- Add Binary
e
- Design Tic-Tac-Toe
e
- Read N Characters Given Read4 II - Call multiple times
- Ez python way, 2. other java/c++ way with array buffer.
- Valid Palindrome II
e
- 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!
- Longest Consecutive Sequence
e
- Implement Rand10() Using Rand7()
e
172 Trailing Zeros
math
- Employee Free Time
Do K-Way Merge Idea when you get to that lesson :)
- Encode and Decode Strings
e
- 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)
- Reverse Words in a String III
e
- Valid Number
e
- Course Schedule III
e
- Maximum Frequency Stack
e
- Maximum Length of a Concatenated String with Unique Characters
e
- Unique Paths
memo, weird matrix layout, try to understand and do yourself dp iteration, look at most recent submission
- Binary Search
e
- Analyze User Website Visit Pattern
e
- Populating Next Right Pointers in Each Node II
I used solution article, keep with sachin my boi, other discussion solutions are gay as fuck
- Validate Binary Search Tree
try iteration(stack), and in-order next time too