Click here for the google spreadsheet organizing the questions by category and linked to the solution I wrote for each of them. This is always up to date with the README (with the power of a python script and GitHub workflows).
Number | Question | Hints | Python Solution | C++ Solution |
---|---|---|---|---|
1 | Two Sum | Use a hash table to keep track of the indices of the numbers you've encountered so far. | Python Solution | C++ Solution |
24 | Swap Nodes in Pairs | Implement both the iterative and recursive solution. What do we do if the linked list has an odd number of nodes? | Python Solution | |
56 | Merge Intervals | Sort the intervals by increasing start time. | Python Solution | C++ Solution |
66 | Plus One | Try iterating through each digit backwards. What do you do when the digit is a 9? | Python Solution | |
88 | Merge Sorted Array | Look at one element from each of the arrays, compare them, and make a decision depending on their relation to each other. | Python Solution | |
94 | Binary Tree Inorder Traversal | Make sure you know how to implement this recursively. The iterative solution is a lot trickier. | Python Solution | |
102 | Binary Tree Level Order Traversal | Keep track of the child nodes of ALL the nodes in the current level. That will be the next level you will traverse. Rinse and repeat until none of the nodes in the current level have children. | Python Solution | |
122 | Best Time to Buy and Sell Stock II | What should we do every time there is a valley followed by a peak in price? | Python Solution | |
206 | Reverse Linked List | Try a recursive solution. Split the list up into the first node and the rest of the list. | Python Solution | |
217 | Contains Duplicate | Maintain a hash set that keeps track of the numbers we've encountered so far. | Python Solution | C++ Solution |
344 | Reverse String | Use the two pointer approach. Try implementing an iterative and recursive solution. | Python Solution | |
392 | Is Subsequence | Use two pointers to iterate through the two strings simultaneously. | Python Solution | |
409 | Longest Palindrome | Create a hash table keeping track of the number of occurrences of each character. How many of each can we include in our longest palindrome? | Python Solution | |
455 | Assign Cookies | Sort the greed factors and cookies in decreasing (or increasing) order. What can we do with these sorted versions of the inputs? | Python Solution | |
763 | Partition Labels | How can be apply a modified version of the merge intervals algorithm to solve this question? | Python Solution | |
771 | Jewels and Stones | Python Solution | ||
921 | Minimum Add to Make Parentheses Valid | Keep track of the number of open "(" parens as you iterate through the sequence. | Python Solution | |
1002 | Find Common Characters | Keep track of the common characters and their occurrences in a hash table. | Python Solution | |
1207 | Unique Number of Occurrences | Keep track of the numbers and their number of occurrences in a hash table. | Python Solution | |
1338 | Reduce Array Size to The Half | Create a max heap sorted by the number of occurrences of each number | Python Solution | |
1338 | How Many Numbers Are Smaller Than the Current Number | Maintain a running sum in an array | Python Solution | |
1512 | Number of Good Pairs | Keep track of number of occurrences in a hash table. | Python Solution |