For now mainly focused on leetcode algorithms.
Problem solving techniques are well-known and buzz words most of the times.
For example: DP/Divide & Conquer, however for specific problems, it's normally very hard to get it right.
During the time of solve all those problems, I have found those tips really useful:
-
Play around the problem with some concrete examples, understand the problem deeply is key to solve it.
-
Write automation test for it, this is really useful for make more changes.
-
Whenever you find there are situations your solution missed, step back & and rethink if the direction is right.
-
Try best to reduce the problem into some well-know categories, it is normally pretty hard to implement an algorithm from ground.
- ReversePair493
- CountOfRnage327
- CountSmaller315
All of those challenges shares common stuff:
- N^2 algorithm is exist and easy to do
- NlgN algorithm are much harder
- Stable sort with merge sort(NlgN)
- Do count during the merge phase
- It is always easier to separate the concerns by split the sort with count
132 Recursion solution 126 DFS/BFS combined solution 174 Recursion solution