by Sebastian Weszler
- Most frequently occurring item in the list.
- Common elements in two sorted lists.
- Is list a rotation of another list.
- Corporate Flight Bookings - Leetcode 1109 [difference_array]
- Find best value. Sum of Mutated Array Closest to Target. [binary_search]
- K Closest Points to origin [quicksort]
- Rotate 2D list by 90 degrees
- Non-repeating character.
- One way string.
- Compare strings by which one is strictly smaller
- Matching Parentheses
- Count and Say
- Encode Number - Leetcode 1256
- Assign numbers in Minesweeper
- Find where to expand in Minesweeper
- Course Schedule - Leetcode 207 [dfs, bfs, kahns_top_sort] - WIP
- Stable Wall (Google Kickstart 2020 Round C) - WIP
- N-th element of a linked list
- Delayed Projects - WIP
- Is it a binary search tree
- Lowest common ancestor of two items in binary tree
- Maximum level sum
- Knapsack problem
- Plates (Google KickStart 2020 Round A)
- Alien Piano (Google KickStart 2020 Round D)
- Two City Scheduling - Leetcode 1029
- Analyse solution on paper.
- Big picture first, then details. If this is large problem, break it down into smaller functions (representing steps or different cases), keep your algorithm loosely coupled with the data structure. Use known data structure.
- B.U.D.
Bottleneck - Identify a bottleneck and get rid of it. An example problem could be two lists that we must iterate to find a common items. Instead of iterating both lists we can store one of them in a data structure that allows us quick (constant) look-up.
Unnecessary work - Try a brute force solution and look for unnecessary work that can be eliminated.
Duplicated work - The same as for unnecessary work, try to eliminate operations that are duplicated in your brute force solution. - Space/Time tradeoff. Most of the time when you want to improve your algorithm and make it working faster it must use more space, which means you must store more data in memory. This should lead you to choosing proper data structure that eventually helps you solve this problem optimally.
- D.I.Y (do it yourself) Use big example and try to solve it manually, you might be able to reverse engineer your thought process (your brain algorithm)
- Communicate your thoughts, speak about it. Make sure all your assumptions are correct.
- While working with more complicated recursive functions use The Call Stack to visualize execution for each function call.
- It might not be applicable to many problems, but whenever the optimization of the algorithm is needed it's worth to consider next known better time complexity Big O Cheat Sheet. For instance if O(n) isn't enough try O(logN), which can be achieved by dividing your set of data by 2 and run your function recursively until finding a result. (Divide and conquer)
- From a brute force solution find a pattern or sequence, if this is arithmetic or geometric sequence you can apply mathematical equation to find sum of a sequence or nth element.
- To find patterns, consider all test cases and analyse them one by one, use bigger sets of input data.
pytest ./