top of page

What I learned after I completed the first 50 Leetcode problems




Even now in 2024, as the AI tools are getting more and more compelling, you might wonder if relentless practice on Leetcode, focusing on data structure and algorithm, is still necessary. My answer is a resounding yes. I will explain why later and also share the methodology pattern for working on the Leetcode and how to perform well when solving problems in front of the whiteboard.


First, here is a YouTube video sharing the knowledge of how to defeat the coding interview. Please watch it if you have never watched it.


It lists out all of the software topics and how to prepare your mindset when you are either in the preparation stage or in the interview session. The greatness is the YouTuber provides you with a list of points that could be very helpful for you, such as "Be experienced", "Algorithm for solving the algorithm problems", and "Be smart". In this article, I will share deeper experiences here when I was using the same pattern, or you can say methodology on the second one "algorithm for solving the algorithm problems." I will give you a condensed version and a quick acronym to remember this process.


Algorithm for solving algorithm problems

The pattern, or you can say methodology, for solving problems when you encounter a new coding challenge can be boiled down to only five action items and is very easy to remember. They are as follows:


  1. Visualize

  2. Approaches

  3. Pseudocode

  4. Implement

  5. Refine


Visualize

The first is visualization. You may get a problem directly described by the interviewer in the online video room, or directly face the challenge that you are just working with in your office. The first thing is to visualize them on paper or a whiteboard. For example, currently, you get two sorted arrays, please try to merge them and sort them in the non-decreasing order. At this point, you should try to draw down two sorted arrays and write down any constraints that you get from the interviewer or problems, such as the range of values and how long are the arrays. Luckily, when you are practicing the Leetcode, they've already done this for you with some examples and sometimes even with great drawings along with the problems. At this time, you can just use the same example and write them down again. This is because using your pen or pencil to draw some pointers or auxiliary information is so much easier than drawing on computer software.


Visualization greatly helps people quickly grasp the big picture. By simply moving your pointers or inserting and deleting an element in a data structure, you might by chance come up with some ideas and even discover any possible difficult points. So, please remember to sketch the problem situation, list the constraints, and try to draw moving objects to vividly illustrate the running situation.


One more thing, you might think about how to draw a quick and clear picture for the first time, I would say there is no way to get better if you are just a beginner. Remember practice makes perfect. So what you can do is keep trying.


Approaches

The second is approaches. Use your drawing to intuitively think of your first solution. Of course, most of the time if you have little experience in problem-solving you may think of some low-performance solution, (like selection sort, which is very straightforward if you ask children.) But don't worry. The key here is the transition from visualization to a correct approach. You need to warm up your brain and start to load up several different techniques you have learned before. So in this stage, you have to keep drawing something like data flows, moving pointers, and even a queue to conclude a workable and even optimal solution from your brain. Once you connect all your thoughts and come up with a possible solution, you are good to start the next stage.


Pseudocode

This stage is not necessary if you feel that the approach is defined and can be implemented very quickly in your IDE or on a whiteboard. The benefits of this stage are: firstly you can conclude your thoughts in a couple of English expression lines to walk through the whole running process and see if at least some test cases are passed. The second is you can use pseudocode to formally discuss with an interviewer about your ideas and give an estimate of time/space complexity. Back and forth to bounce ideas between you and the interviewer is very important when you are in the interview session. This is a critical time to let the interviewer know your thinking path and your communication skills. Besides, I believe this is also the time the interviewer would know if it is fun or smooth to work with you. Thirdly, this is also a great time for your interviewer to give you a heads-up or a gentle reminder if you miss something in your pseudocode. How should the pseudocode look depends on how you learn from your textbook. I will recommend a book here that you can review again on the data structure and algorithm, and also you can write similar pseudocode as the author did. https://www.crackingthecodinginterview.com/


Implement

I think this stage is so common that I don't have to explain more. Of course, you should write down your code in your IDE and make sure it is runnable. But as for the Google interview, they will ask you to write your code directly on the online Google document without any IDE help. (This is challenging.) So it might also have to get a hundred percent hands-up practice so that you won't have too stupid wrong syntax for some functions or dependencies naming. For example, you forget to write the return type before the function in Java Language.


I won't give any more suggestions here. I believe if you have work experience, writing code is nothing more than normal, but if you are just a beginner in the programming world, I believe you should start with one programming language textbook or online tutorial to familiarize yourself with how to write runnable code.


Refine

This stage is also very important. Many inexperienced individuals may believe that writing perfect code on the first try is the right direction. However, in reality, aiming for perfection right away isn't necessarily the best approach. We aren't ChatGPT or any other large language models; making mistakes or producing slightly imperfect code is part of the process. What truly matters is maintaining a positive attitude, being willing to acknowledge the need for revisions, and understanding how to make those improvements. At this point, discussing concepts like unit testing and performance tuning with your interviewer becomes valuable. With that being said, being open about your intention to refine your work later, and explaining how you plan to do so, demonstrates your commitment to enhancing code quality.


Summary

You will find these five stages together with only the leading letter assembling as "VAPIR". It is not a real vocabulary, but at least it's easy for me to memorize and gear up myself to solve the coding problem. But the YouTube video previously I mentioned is full of detailed explanations and long stage names. That's why I use the same pattern and summarize this easy-to-remember acronym. And besides, the pronunciation of "VAPIR" is also cool like a superhero having the magical power to vaporize rivals in just a single second, like the imagination below, LOL.



Let's circle back to the beginning, I have said the practice of Leetocde still shows the importance in this AI age. Why is it? If you have seen the Iron Man series of movies from Jr Robert Downey, he has a cool assistant named Jarvis who is always on the side working and fighting with Iron Man. From my perspective of view, I believe Jarvis is growing and getting smarter along with how Iron Man interacts with him. You don't have to be as fast as Jarvis calculating or collecting the data, but being smarter and having more critical thinking than Jarvis is the way to work with robots.



I welcome your suggestions! If you have a more powerful experience or a different term to help remember these five action items, please don't hesitate to reach out or drop me a line. I'd also love to hear if my insights have been helpful to you. Best of luck on your Leetcode practice journey!"




1 commentaire

Noté 0 étoile sur 5.
Pas encore de note

Ajouter une note
Invité
29 mars
Noté 5 étoiles sur 5.

Great view!

J'aime
bottom of page