This article tried to build a right mindset with respect to leetcoding.
Good algorithm designer stands on the shoulders of giants .
- Rather than laboring from scratch to produce new algorithm for every task, good algorithm designer can figure out what’s known about a particular problem.
- Rather than reimplementing popular algorithms from scratch, good algorithm designer seeks existing implementation to serve as a starting point.
- Good algorithm designer is familiar with many classic algorithmic problems, which is proved to sufficiently model most any applications.
So, for leetcoding, we’re practicing the ability to map a new problem to an already known problem .
How do we practice leetcoding?
Imagine you have a leetcode problem during the interview? It’s not about you make the problem accepted or not but you fully communicate your idea or thought of how to solve the problem to show your problem solving skill. Again, your goal is not to become CP programmer but to ace the interview . So, what your daily practice should focus on presenting numerous alternatives with pros & cons of each algorithm and data structure and trade-off between time and space complexity. This’s why clarifying questions is always very important.
Basically, I list 5parts that we should ask myself when leetcoding
- Problem Clarification: to show you will clarify the requirements when encountering a problem by simply asking range of input, any constraint of input and expected output for edge case.
- Problem Understanding(Optional): go through examples to make sure you fully understand the problem. Only when problem description is a bit complicated.
- Problem Formulation
- Thought Process
- Time Complexity Analysis
- Test Case: to show you will test your algorithm by walking through your algorithm with a simple test case after the code.
Please see my code in other articles as an example of how to do the above.
Note: How to select test cases? Usually, edge case and extreme case are good starting points. But, if you can find any interesting cases that showcase scenarios which your algorithm has to handle differently, that would be good.
. Chapter 1, The algorithm design manual, 2nd edition
. patterns for coding question, https://www.zhihu.com/question/280279208/answer/879710574
. Video from Youtuber Techlead
. Leetcode problem categorised by topics, https://cspiration.com/leetcodeClassification