To get better at coding interviews, you can practice LeetCode. To get better at LeetCode, you can study algorithms and data structures. To understand how algorithms and data structures work, you can study discrete math. When you study or practice one thing in order to understand or improve another thing, you are relying on a process called transfer.
To learn more about the ideas in this tip, see How Much Transfer Should We Expect Between Skills? by Scott Young.
Increase the overlap between skills
To help a skill transfer from one context to another, make sure there is an overlap between the two contexts. Programmers practice LeetCode problems because they expect the problems they’ll encounter in an interview will resemble the ones on the LeetCode problem list. But if we only practice solving problems and submitting them to an online judge, we shouldn’t expect those skills to transfer when the interviewer asks us to explain how our solution works, since the online judge doesn’t care about that.
Take advantage of increased expertise
A benefit of gaining expertise in an area is gaining more abstract skills that transfer more efficiently to other contexts. If you learn how to solve specific problems, your skills will only transfer to problems that fit the patterns you learn. But if you learn the process of finding a solution, you can apply it to a wider variety of problems.
Learn the fundamentals
Fundamental knowledge doesn’t directly transfer to practical skills. Being able to prove that Quicksort runs in average $O(n \log n)$ time doesn’t mean you can implement Quicksort, and being able to implement Quicksort doesn’t mean you can solve any LeetCode problem that requires a divide and conquer approach. However, understanding the fundamentals can help you learn more advanced topics. So it indirectly contributes to transferrable skills.
Use the right type of practice
According to cognitive load theory, the limited capacity of working memory can impede learning if we don’t take it into account in our practice. When we first study a topic, it’s best to use examples and practice smaller components that fit into working memory. For example, it’s best to practice easier problems when learning a new algorithm. Once you can fluently implement the algorithm in its basic form, you no longer have to keep the implementation details in working memory. Your fingers know how to implement it with little input from your brain. That frees up cognitive capacity to consider the details of a more complex problem that is based on that algorithm.
Don’t just practice the target activity
To maximize transfer, it may seem like you should just practice the activity you eventually want to master. For coding interviews, this would mean spending time in mock interviews. But although this would give you a lot of practice in explaining your thought process while solving problems, it wouldn’t be the most efficient way to learn every LeetCode problem type. Learning new problem types requires concentrating on the details of the problem, without having to think about the other parts of the interview.
Similarly, the best way to learn to solve LeetCode problems isn’t to spend 100% of your study time solving problems. Time spent studying and understanding the underlying algorithms and data structures can make problem-solving practice more efficient.
This year, I’m publishing a series of tips for effective LeetCode practice. To read the tips in order, start with A Project for 2023.