Currently practicing: NeetCode Blind 75
- For tree problems, recursive DFS is cleanest to implement.
1. Blind 75 Two Sums Make a map of item and index. Check if target - currentItem exists. Oct 29, 2022
2. Blind 75 - Contains Duplicate Create a set and put items in one by one while checking if `num` is already there. Oct 30, 2022
3. Blind 75 - Group Anagram compare the count of letters in each word and put group them in a map Oct 30, 2022
4. Blind 75 - Top K Frequent Elements - IMP count all numbers. sort. and return top k. Use streams to make it cleaner. or use bucket sort. Oct 30, 2022
5. Blind 75 - Valid Anagrams
check if the length is the same.
find the difference in the count of letters in both numbers.
since there are only 26 letters, you can count in a single int array of 26.
index = char - 'a' Oct 30, 2022
6. Blind 75 - Product of Array Except Self
first right to left while multiplying.
Then second left to right while multiplying.
This can be done in a single array and one extra product variable Nov 4, 2022
7. Blind 75 - Valid Palindrome Have 2 pointers. One at the start other at the end. Skip if `!Character.isLetterOrDigit` and compare with `Character.toLowerCase` Nov 6, 2022
8. Blind 75 - Valid Parentheses
God-level solution - iterate.
If an opening bracket is found, put the closing bracket in a stack.
If the closing bracket is found, pop and check for equality. Nov 6, 2022
9. Blind 75 - Best Time To Buy And Sell Stock Make sure the left pointer is always the lowest yet. Keep checking the difference between left and right. And return max. Nov 13, 2022
10. Blind 75 - Invert Binary Tree Swap left and right. Then repeat for those nodes. Nov 16, 2022
11. Blind 75 - Linked List Cycle Have a fast pointer and a slow pointer. fast increases by 2. slow increases by 1. if both become the same then the cycle exists. if fast one reaches end then no cycle exists. Nov 16, 2022
12. Blind 75 - Maximum Depth of Binary Tree go to each depth, incrementing a depth counter by 1. return max of it. Nov 16, 2022
13. Blind 75 - Merge Two-Sorted Lists Iterate over both and store minimum one in current; Increment in the list from where minimum came. Once one of the lists is empty, empty the other one. Nov 16, 2022
14. Blind 75 - Reverse LinkedList Similar to swapping two numbers. Start with prev as null and current and keep swapping next. Return prev because that's the last value. Nov 16, 2022
15. Blind 75 - Same Tree Nov 16, 2022
16. Blind 75 - Subtree of Another Tree Check if root is same as subtree or root.left is same or root.right is same; Nov 16, 2022
17. Blind 75 - Number of 1 Bits Check if the last bit is 1 by (n&1). Do the right unsigned shift (logical shift >>>). Loop. Nov 20, 2022
18. Blind 75 - Reverse Bits Get the last bit of value from the original. append to the reverse one. shift reverse one to the left. instead of adding, you can do `or` because after the shift last value will be 0. Imp - iterate 32 times only. Nov 20, 2022