# | Problem Name | Solution | Description |
---|---|---|---|
1 | Two Sum | Solution | Use a hash map to keep track of seen numbers |
121 | Best Time to Buy and Sell Stocks | Solution | Iterate over prices, if found lower price update buy date else keep searching for better profit |
217 | Contains Duplicate | Solution | Compare len of array vs len of set; alternatively add elements to set if element already seen return true |
238 | Product of Array Except Self | Solution | Calculate Prefix on one pass and then multiple with postfix on next pass |
53 | Maximum Subarray | Solution | Iterate while keeping track of cur sum, if it is negative discard it then start cur sum again. Take maximum of cur sum and maximum sum seen so far |
152 | Maximum Product Subarray | Solution | Iterate while keeping a curmin and curmax, update it when seeing a number, negative x negative will update in max being updated |
153 | Find minimum in Rotated Sorted Array | Solution | Set left to first element, right to last value, find middle. If middle is smaller than left than search left else search right |
33 | Search in rotated sorted array | Solution | Use middle to find if you're in the left part of the sorted array or the right part, then update search area based on the middle value and the extreme value |
15 | 3Sum | Solution | O(n2): Sort the array, Fix a starting point then look for left and right, if total > 0, move right inwards, else if target < 0, move left outwards, otherwise move to next fixed number |
11 | Container with Most Water | Solution | Two pointer solution, start with extremes move whichever side is lower to the opposite side |
191 | Number of 1 Bits | Solution | Mod number with 2, then keep count, shift number using bit shift operator |
338 | Counting Bits | Solution | Dynamic Programming, keep an offset (power of two) and for every number find significant digit and add 1 for that and resst is the same number of bits as number - offset, eg: 7 = 1 + same as 4 |
268 | Missing Number | Solution | Subtract from sub of n numbers formula or xor with every number in that range |
190 | Reverse Bits | Solution | Iterate over length, find ith bit by doing and, shift that by n - i and or it with result |
70 | Climbing Stairs | Solution | Fibonnaci Series Sum, keep track of last two step solutions, set the preceding solution to the sum of the two |
322 | Coin Change | Solution | Dynamic Programming: For each amount in range(1, amount+1), the solution = 1 + cur_amount - coin for every coin and then take the minimum |
300 | Longest Increasing Subsequence | Solution | Dynamic Programming, starting with the last element try to add elements |
1143 | Longest Common Subsequence | Solution | |
242 | Valid Anagram | Solution | Create a hash map of the counts for each character, or sort the strings |
167 | Two Sum II | Solution | Left and right pointers, if too high move right to the center, if too low move left to the center |
198 | House Robbers | Solution | Maintain house 1 and house 2, update house1 to house 2, and house2 to max(house1+n, house2) |
235 | Lowest Common Ancestor of a Binary Tree | Solution | Three cases: Either the values are split, then root is the LCA otherwise search left or right based on values |
202 | Happy Number | Solution | Keep a set to track numbers already visited, loop |
155 | Min Stack | Solution | Keep a second list / or track of mins at every point |
203 | Remove Linked List Element | Solution | Move the head till we keep getting the target val then remove from the rest of the list while tracking prev node |
35 | Search Insert Position | Solution | Binary search, return position based on target vs left / right |
1046 | Last Stone Weight | Solution | Heapify the stones list, python only has min heap so multiply everything by a -1 to get max heap |
26 | Remove Duplicates from Sorted Array | Solution | Keep a pointer to track unique values, iterate and replace at pointer spot |
263 | Ugly Number | Solution | Keep dividing by the specified prime numbers while it is divisible, if at the end n=1 then return true else false |
58 | Length of Last Word | Solution | .split() recognizes words, then check len of last element |
929 | Unique Email Addresses | Solution | |
929 | Two Sum - Alternate | Solution | |
929 | Map Reduce | Solution | |
929 | Sort Version Number | Solution |
python
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||