- Mapping & Arrays
- Stack
- Two Pointer
- Binary Search
- Matrix
- Sliding Window
- Linked List
- Trees
- Tries
- Heap & Priority Queue
- Backtracking
- Graphs
- Dynamic Programing
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Two Sum | Python | Easy | Check for diff and map value to index |
| Roman To Integer | Python C++ | Easy | Map Roman to Int |
| Find Words That Can Be Formed by Characters | Python | Easy | Freq Count |
| Remove Element | Python | Easy | Keep track of num of elements not in nums |
| Pascal Triangle | Python | Easy | Check prev values to find curr |
| Unique Email Addresses | Python | Easy | Use set |
| Find the Difference of Two Arrays | Python | Easy | create ans = [[], []] and loop thru nums1 and nums2 |
| Find the Index of First Occurence in String | Python | Easy | Slicing |
| Search Insert Position | Python | Easy | Loop through and compare |
| Contains Duplicate | Python C++ | Easy | Use set to check |
| Contains Duplicate II | Python | Easy | Map mp[num]: i |
| Happy Number | Python | Easy | Keep track of visited numbers |
| Isomorphic Strings | Python | Easy | Map curr s_char with t_char and keep track of used t_chars |
| Valid Anagram | Python C++ | Easy | Map with occurences |
| Zigzag Conversion | Python | Medium | Create list of empty strings size of rows -> check if index at end of list |
| Search In Rotated Sorted Array | Python | Medium | Binary Search with first and second half of array |
| Max Number of K-Sum Pairs | Python | Medium | Map difference to count and check if num in dict |
| Group Anagams | Python C++ | Medium | Use sorted and hash with list |
| Minimum Number of Frogs Croaking | Python | Medium | Update new frog when arrive at 'c' -> map char with count |
| Longest Consecutive Sequence | Python C++ | Medium | Keep track of previous index |
| Prodcut of Array Except Self | Python | Medium | create left and right list [1] * len(nums), get product of left and right in nums except [0] and [-1], match index and multiply |
| Divide Array Into Arrays With Max Difference | Python | Medium | One pass |
| Top K Frequent Elements | Python | Medium | Bubble sort |
| Longest Consecutive Sequence | Python | Medium | Convert nums to a set and check if start of sequence -> end of sequence |
| Find the Winner of an Array Game | Python | Medium | Compare 0th index continuously |
| Last Moment Before All Ants Fall Out of a Plank | Python | Medium | Find max ant from falling |
| Minimum Amount of Time to Collect Garbage | Python | Medium | Calculate (total time cost) + (trash count) |
| Count Nice Pairs in an Array | Python | Medium | Map num-rev : count |
| Candy | Python | Hard | Two pass and map index: candy_ct |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Valid Parenthesses | Python C++ | Easy | Pop from stack if valid |
| Evaluate Reverse Polish Notation | Python | Medium | Pop 2x and append |
| Min Stack | Python | Medium | Append and tuple and compare with top of stack |
| Simplify Stack | Python | Medium | Split string by "/" then one pass with stack |
| Daily Temperatures | Python | Medium | Use stack and append with (val, index) then sliding window |
| Car Fleet | Python | Medium | Create list of pos and speed then reverse list to get distance (target - pos)/speed |
| Insert Delete GetRandom O(1) | Python | Medium | Swap with top of stack and map {val: index} |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Palindrome Number | Python C++ | Easy | Cast to string and 2 pointer |
| Longest Common Prefix | Python | Easy | Create helper function to compare with first string in list |
| Remove Duplicates from Sorted Array | Python | Easy | Recursion or 2 pointer |
| Container with Most Water | Python | Medium | Two pointer |
| Two Sum II - Input Array is Sorted | Python | Medium | Two pointer |
| 3Sum | Python | Medium | Two pointer and create a visited set with tuples |
| Remove Duplicates from Sorted Array II | Python | Medium | Replace duplicate with long int |
| Trapping Rain Water | Python | Hard | 2 Pointer and keep track of left and right max |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Binary Search | Python | Easy | Create left,right, and middle pointer |
| Search a 2D Matrix | Python C++ | Medium | Find row by comparing 0th and -1th index -> regular binary search on row |
| Find Minimum in Rotated Sorted Array | Python | Medium | If right pointer greater than curr pointer move window down |
| Find First and Last Position of Element in Sorted Array | Python | Medium | Two pass binary search |
| Search in Rotated Sorted Array | Python | Medium | Check left -> mid and mid -> bounds to see if sorted |
| Koko Eating Bananas | Python | Medium | Binary search and keep track of amount of bannas ate |
| Time Based Key-Value Store | Python | Medium | Map key to list of lists and binary search(left = 0, right = length of key)) |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Matrix Diagonal Sum | Python C++ | Easy | Two pointer |
| Special Positions in a Binary Matrix | Python | Easy | Map r,c to counts of '1' |
| Valid Sudoku | Python C++ | Medium | Map with R, C, and 3x3 |
| Spiral Matrix | Python | Medium | Keep track of L,R,T,B |
| Set Matrix Zeros | Python | Medium | Create set for rows and cols with zeros |
| Search a 2D Matrix | Python | Medium | Binary Search |
| Game of Life | Python | Medium | Use set to store indexes for zeros and ones |
| Rotate Matrix 90 Degrees | Python | Medium | Take transpose then go through range n//2 then swap [i][j], [j][i] <-> [i][n-j], [i][j] |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Best Time to Buy and Sell Stock | Python | Easy | Keep track of highest |
| Maximum Average Subarray l | Python | Easy | Find max sum -> return max_sum/k |
| Best Time to Buy and Sell Stock II | Python | Medium | Add to profit if profit[i] < profit[i+1] |
| Longest Substring Without Repeating Characters | Python C++ | Medium | Slding window |
| Permutation in String | Python | Medium | Sliding window |
| Merge Intervals | Python | Medium | Sort by start time -> sliding window |
| Maximum Number of Vowels in a Substring of Given Length | Python | Medium | Find count from 0 -> k then sliding window k -> len(s) |
| Minimum Size Subarray Sum | Python | Medium | Sliding window |
| Find Longest Subarray By Sum | Python | Medium | increase window size until sum > target then minimize left side of window until > target |
| Minimum Window Substring | Python | Hard | Monotonic decreasing queue, make sure right-left index is < k, append to res when right >= k-1 |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Reverse Linked List | Python | Easy | Keep Track of prev curr and next |
| Merge Two Sorted Lists | Python | Easy | Traverse and connect head to remaning list1 or list 2 |
| Remove Duplicates From Sorted Linked List | Python | Easy | Keep track of next node and check if curr.next |
| Linked List Cycle | Python | Easy | Use slow and fast pointer to check for overlap |
| Add Two Numbers | Python | Medium | Go left to right and keep track of carry |
| Remove Nth Node From End of List | Python | Medium | Create dummy node and 2 pointer |
| Swap Nodes In Pairs | Python | Medium | Keep track of curr.next and curr.next.next |
| Reverse Linked List II | Python | Medium | 3 pass and use multiple pointers |
| Copy List With Random Pointer | Python | Medium | Map old node to new node |
| Partition List | Python | Medium | One pass with 2 dummy nodes |
| Reorder List | Python | Medium | Find middle using 2 ptr, reverse list end -> middle, merge |
| LRU Cache | Python | Medium | Use a map and deque |
| Remove K from List | Python | Medium | check for curr.next.next and return head if head.val != k |
| Convert Sorted Linked List to Binary Search Tree | Python | Medium | Create list of vals and dfs helper function |
| Split Linked List in Parts | Python | Medium | Get length of list and append to ans when part size hit |
| Merge k Sorted Lists | Python | Hard | Create helper function to merge 2 lists and merge first list with rest |
| Reverse Nodes in k-Group | Python | Hard | Use stack to keep track of k nodes |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Binary Tree Preorder Traversal | Python | Easy | DFS |
| Sum of Left Leaves | Python | Easy | DFS |
| Binary Tree Postorder Traversal | Python | Easy | Recrusive DFS or use stack and BFS iterativly and return reversed list |
| Count Complete Tree Nodes | Python | Easy | BFS and add by length of queue |
| Bianry Tree Paths | Python | Easy | DFS and checkk if not root.left and not root.right |
| Path Sum | Python | Easy | DFS and keep track of current sum |
| Mode in BST | Python | Easy | DFS and map frequency |
| Convert Sorted Array To BST | Python | Easy | Use recursion and keep track of middle to find sub node |
| Maximum Depth of Binary Tree | Python | Easy | recursive dfs and return 1 + max of left and right subtree |
| Minimum Depth of Binary Tree | Python | Easy | DFS and update node count in paramenter |
| Invert Binary Tree | Python | Easy | Swap nodes the recurse |
| Diameter of Binary Tree | Python | Easy | DFS and check for max(left+right+1,max(left,right)) |
| Balanced Binary Tree | Python | Easy | Create bool variable for ans, dfs and check if max(left,right) - min(left,right) > 1, change ans |
| Same Tree | Python | Easy | dfs and append to 2 lists |
| Subtree of Another Tree | Python | Easy | dfs until root.val == subRoot.val and use helper function for same tree |
| Lowest Common Ancestor of BST | Python | Medium | DFS until split (root > p.val and root < q.val (vise versa)) |
| Sum Root to Leaf Numbers | Python | Medium | DFS and keep track of int with str |
| Pseudo-Palindromic Paths in a Binary Tree | Python | Medium | DFS -> keep cts of values -> check if max odd value is <= 1 |
| Path Sum ll | Python | Medium | DFS with stack and check when sum(stack) = target |
| Path Sum lll | Python | Medium | Brute force and get sum of every root |
| Amount of Time for Binary Tree to Be Infected | Python | Medium | Convert to undirected graph then dfs |
| Maximum Difference Between Node and Ancestor | Python | Medium | Return min and max pairs to calculate diff |
| Symetric Tree | Python | Medium | DFS with invert recursive call |
| Binary Tree Level Order Traversal | Python | Medium | BFS |
| Find Largest Value in Each Tree Row | Python | Medium | BFS |
| Kth Largest Sum Binary Tree | Python | Medium | BFS |
| Binary Tree ZigZag Level Order Traversal | Python | Medium | BFS and use list slcing to reverse |
| Maximum Level Sum of Binary Tree | Python | Medium | DFS and check if not root.left and not root.right |
| Count Nodes Equal to Average of Subtree | Python | Medium | DFS and return tuple of previous edges and sum to avoid brute force |
| Validate Binary Search Tree | Python | Medium | DFS and keep track of curr min and max |
| Binary Tree Right Side View | Python | Medium | Create left and right deque and append from end of deque |
| Count Good Noes in Binary Tree | Python | Medium | DFS and keep track of curr max |
| Kth Smallest Element in BST | Python | Medium | In order Traversal -> return k-1 |
| Maximum Binary Tree | Python | Medium | Get max of nums -> -> dfs with left and right subarray |
| Print Binary Tree | Python | Medium | Get height -> create matrix -> dfs |
| Binary Tree Maximum Sum | Python | Hard | DFS and compare left and right recursive calls with max(0,left or right) to get edge case of root itself being max |
| Serialize and Deserialize Binary Tree | Python | Hard | DFS to turn tree to str then use refernce incremnter to loop through split data |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Implement Tries (Prefix Tree) | Python | Medium | Create node class of hashmap to map each char to a unique path |
| Design Add and Search Words Data Structures | Python | Medium | Create node class of hashmap and dfs for search (explore all paths if char == '.') |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Kth Largest Element in a Stream | Python | Easy | Keep min heap size of k and return root |
| Seat Reservation Manager | Python | Medium | Min heap |
| Eliminate Maximum Number of Monsters | Python | Medium | Use min heap and push when monster will arrive to city by dist[i]/spped[i] |
| Last Stone Weight | Python | Medium | Max heap |
| K Closest Points to Origin | Python | Medium | Min heap with tuple |
| K Largest Element in Array | Python | Medium | Max heap or sorted |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Subsets | Python | Medium | DFS use stack to take care of 'dont include' descison |
| Subsets ll | Python | Medium | Sort -> dfs and do not include duplicates in choices |
| Generate Parentheses | Python | Medium | DFS -> compare open with n -> compare open with closed |
| Combination Sum | Python | Medium | DFS until index > lenth or sum(stack) == target or sum(stack) > target |
| Combination Sum ll | Python | Medium | Sort list -> dfs backtrack -> skip over duplicates |
| Word Search | Python | Medium | DFS and keep track of visited and replace board with original values once depth reached |
| Permutations | Python | Medium | Keep track of choices with boolean list size of nums |
| Combinations | Python | Medium | Backtrack |
| Beautiful Arrangement | Python | Medium | Backtrack |
| Non Decreasing Subsequences | Python | Medium | Backtrack and store perms in a set |
| Palidrome Partitioning | Python | Medium | Dfs and check for palidrome |
| Sudoku Solver | Python | Hard | Backtrack with checking if next empty spot is valid |
| N-Queens | Python | Hard | Backtrack and keep tract of pos and neg diags (r+c) and (r-c) |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Flood Fill | Python | Easy | DFS |
| Number of Islands | Python | Medium | DFS and change '1' to random char |
| Max Area of Island | Python | Medium | DFS use list to store counts to avoid counter resetting |
| Pacific Atlantic Water Flow | Python | Medium | Find paths for atlantic and pacific and store in a set |
| Surrounded Regions | Python | Medium | Find invalid regions using dfs and store in a set -> find valid replacements going through orginal board |
| Rotting Oranges | Python | Medium | BFS and check neighbors |
| Course Schedule | Python | Medium | DFS topological sort |
| Course Schedule ll | Python | Medium | DFS topological sort and check for courses not in prerequisites |
| Clone Graph | Python | Medium | Map node to new node -> dfs |
| Redundant Connections | Python | Medium | DFS |
| Network Delay Time | Python | Medium | Dijkstra algorithm |
| Cheapest Flights Within K Stops | Python | Medium | Dijkstra algorithm using stops as priority |
| Path with Minimum Effort | Python | Medium | Dijkstra + memo |
| Restore the Array From Adjacent Pairs | Python | Medium | Create adj list -> find vertex with outdegree of 1 -> create ans iterativly |
| Minimum Genetic Mutation | Python | Medium | BFS similar to Word Ladder |
| Word Ladder | Python | Hard | BFS and get possible paths by using temp char to replace current word |
| Longest Increasing Path in a Matrix | Python | Hard | DFS and memoization |
| Design Graph With Shortest Path Calculator | Python | Hard | Dijkstra algorithm |
| Problem | Solution | Difficulty | Hint |
|---|---|---|---|
| Climbing Stairs | Python | Easy | Bottom up and find sum of previous 2 steps |
| Min Cost Climbing Stairs | Python | Easy | Bottom up and compare minimum of current cost and next 2 steps |
| Array Max Consective Sum | Python | Medium | Keep track of curr max and global max and use kadones algorithm |