In every age, there is no ill-treatment of those who can learn.

Hello, I’m Yes.

I have been working on algorithms in LeetCode for nearly a year and a half. My view on algorithms has changed a lot in the past year and a half. But to be honest, the interview is the one that supports my progress.

I have mentioned in the previous article that I am an interview driven player, and I enjoy smiling at everything the interviewer asks me. In recent years, algorithm plays an increasingly important role in the interview, so I have spent a lot of energy to overcome the algorithm, which is indeed a little difficult.

I was not a gifted player, and I even felt a little stupid. I was often hit by various blows in the process of writing questions. The most exaggerated one was that I had brushed the same question four times, but I still couldn’t write it after a period of time.

Of course, there is a pep talk (don’t mind my bad handwriting).

After three books of systematic study, a year and a half of brush questions, three columns of many times of study, engaged in a lot of big factory real questions practice, basically a little stable.

This article would like to share some of my experience in learning algorithms for interviews, so algorithm fans and algorithm lovers can close this page, this is a general programmer’s algorithm interview walkthrough.

Last year, I also participated in a topic answer, “In the study of data structure and algorithm, should I choose to implement classic codes by myself or recite them?” , accidentally was chosen to win the lottery, hey hey. I wanted to draw the prize, but I threw away the package, because the two algorithm maps need to be loaded in long cylinders, so it’s not easy to transport. Let’s have a look later.

Let’s see how I answer this question.

In the study of data structure and algorithm, should we choose to implement or recite the classic code by ourselves?

I think the learning algorithm is understanding + continuous practice + deliberate recitation (selective recitation).

Some people may be interested in learning algorithms, very straightforward to say that I am utilitarian learning, and can continue to learn because of the utilitarian heart.

Because of utilitarianism, I want to maximize profits quickly, but haste makes waste. Therefore, I will use a rational learning algorithm under utilitarian circumstances.

First consolidate the foundation, great oaks from little acorns grow. Algorithms are the use of a variety of data structures in accordance with a certain flow, even if you are all kinds of weird algorithms can not escape arrays and linked lists. On top of arrays and linked lists are special functions that make a lot of interesting data structures: queues, stacks, etc.

Data structures evolve because different scenarios have different requirements, so arrays are more appropriate in one scenario and linked lists are more appropriate in another scenario. All you need to know is the advantages and disadvantages of each of them and the scenarios they are used in, and you can know why.

For example, array subscript access is efficient because the memory is contiguous and the AFFINITY for CPU cache is higher. Such use ability swims with ease, aim in the right direction.

2, continue to practice, light said not practice false handle, just look is useless, do not get started into empty.

I do not have the talent of that algorithm, in my opinion I have a certain understanding of the basic data structure, when I see some algorithm problems are still obscure, without that idea, empty head, that can only practice.

When I encounter a topic with no idea at all, I will look for the solution in 5 minutes at most, and maybe 2 minutes. Because of utilitarianism, there are some parts that I think I have no brain and I recognize myself hahaha.

But when I was looking for the solution, I went with a goal that I had to fully understand, not to understand, not to give up, at least I had to understand the joke answer (I take this back, I was too young at the time).

Of course, don’t give up here does not mean that half a day or a day must be done. Sometimes you get stuck, and then the next day, you go out and you come back and it’s all clear.

Through constant practice, your mind will gradually understand these questions, you can better correlation various data structures, that is the feeling comes, you will find yourself getting smart, it is to enter a virtuous cycle, and continue to practice, you will find one day if you didn’t write algorithm when there will be a kind of guilt!

In addition, I will not use IDE to write, I will write directly in LeetCode, one by one, always prepare for the interview questions, yes, it is so utilitarian.

3. Deliberate recitation (selective recitation)

Some people would say that algorithms are to be understood, that rote learning is useless. Yes, understanding is certainly to understand, rote memorization will certainly forget in two days.

But I think that isn’t enough to just understand, understand + practice is can let you make the topic, but can’t let you without thinking of the subject, in the case of the tension of interview, only similar muscle memory can give the interviewer the most strong, slightly nervous may lead to a serial error, one false move may lose the game!

So for those classic code, commonly used such as binary search, fast row, etc. I will deliberately recite, to hear binary search, there are so many codes in my mind, yes I am so utilitarian.

That is to say, we should understand all the algorithms we brush at ordinary times, but I think understanding some classic codes is not enough, and we need to recite them to form muscle memory.

Some people may think, there is nothing to memorize, a lot of practice will be, well actually a lot of practice is the same as recite, right you said you write a dozen times is the same as recite. But I was deliberately back.


Gee, gee, I think I said it well, hahaha.

To add a few points to this answer:

1, master the basic, that is, those commonly used data structures and algorithms, such as queue, stack, heap, sorting, fast sorting, binary, dynamic planning and so on, familiar with these classical data structures and algorithms, transparent know their applicable scenarios.

Solve a problem nothing more than to cover them go up, will not call you innovation absolutely, what you do is to set a template, see what your template chooses to be wrong, set of cooked not cooked.

2, keep practicing, this thing is the most important. Because it’s ok to ask a lot of people to see things, it’s a bit of a drag to get them to start.

But algorithms have to be practiced, there’s not much choice, there’s no need to be clever, unless you have a photographic memory.

Because it’s not in line with normal people’s thinking, so you need to keep practicing, so that your thinking changes, so that when you see this kind of problem, you will have a stress response.

There are two other key points that I want to emphasize:

  • Don’t spend too much time on a problem, a few minutes without thinking on the problem solution, see the problem solution and then understand and write silently.
  • Don’t write in an IDE. There is no association during the interview, and sometimes it is even handwritten, so be prepared and not unprepared.

In fact, the above is about daily learning and brush the routine, and then talk about how to get started.

Get started guide

I chose My column “The Beauty of Data Structures and Algorithms”. I have scanned this column twice. Although I have read other columns, this is enough. It covers almost all the data structure and algorithm books.

I see this entry, the basic routine explanation is very complete, recommend the column first comprehensive look again, each class involved to the code to knock again.

You can study this column in the following order of difficulty and emphasis.

The purpose of the second brush is to extract and summarize. Let me post my previous summary of individual chapters, which is left by participating in the algorithm punching activity.

By the end of the brush, some classical data structures and algorithms are at least familiar, or to say, basically a beginner.

Then go to see “algorithm (4th edition)” this book, although I read three algorithm books but I think this is enough.

Generally speaking, people will recommend books first, after all, books are more comprehensive and more systematic, but I like to do the opposite.

Because books are too thick, thick is easy to discourage, especially if you are not familiar with an area.

Therefore, I prefer to learn the paid columns refined by others first, and the extracted columns are all the key points, so that I have a full understanding of the core knowledge, and then read books to check and fill in the gaps and establish a perfect system.

Because when you read a big head book, you will have a sense of familiarity and resonance after you have already understood the general core knowledge. This feeling can let you read the book from beginning to end.

As for why you have to read the column, because the column is refined after all, and most of the knowledge points in the book are complete, you first absorb the knowledge points refined by others, take other people’s ideas and then go to systematic learning, from which to mix up their own summary, so that things are really yours.

After systematically studying this book, you feel as if you are very powerful?

And it isn’t.

You also need to go into the field and touch the real interview questions.

Of course, I was at the beginning of the brush questions, and not wait for the column, the book is finished before getting started, I suggest during the brush column to brush questions to practice.

I came to know the website LeetCode in 2016. At that time, I saw a graduate student in the same project group using it. He was studying abroad for a master’s degree, and he said it was necessary to use it.

There was no Chinese version at that time, and I looked very advanced in English to play a play, not afraid of you jokes, the first problem will not, can only write violent solution, cycle the sum of two numbers to contrast.

After seeing the solution of the problem suddenly realized, dark scold oneself good stupid, and then continue to brush back a few successful was persuaded, and then there is no and then…

By now, there are more and more questions in LeetCode. It is too “stupid” to brush them in order. There is no need to brush all the questions.

General classic common types are nothing more than BFS, DFS, double pointer, prefix, backpack, binary, linked list, binary tree, sliding window, heap (Top K), stack, dynamic programming, backtracking, sliding window, bit operation, graph, various sorting and so on.

In fact, there are some math problems, I chose to give up, hahaha.

Under normal circumstances the interview also won’t ask math type, as for the above questions, have a very nice algorithm notes help you summarized, very complete, very intimate, page 1730, 20 w, summarizes the major topic, basically every topic with the bosses of their thinking, high quality and attach links, convenient to view the original, I’m just going to show you some random pictures.

This algorithm summary is requested from me, a graduate student who is looking for a job by brush. After that, I plan to provide some 1V1 counseling service on study, resume modification and job hunting route. Please look forward to it

The summary PDF is available at the end of this article.

The problem solving skills

Let me mention one more trick that I personally think is very important: the trunk comes first and then fills in the details. This coding technique is not only about algorithms, but also about everyday code.

Let me use the very simple example of bubble sort to illustrate what this means.

The arrow points to the code that swaps the contents of the two positions, which can be encapsulated like this.

The code in this example is so simple that it’s okay not to encapsulate it, but that’s the idea of encapsulating it.

Generally speaking, the interviewer can see your code online in real time. He can see not only your problem solving, but also your code style, layout, etc., which is also a key part.

So when you have a lot of code, pay attention to the encapsulation of the method, not a bunch of all together.

Trunk first means that, for example, the implementation of the swap method above do not write, you when you have implemented the swap method to use the line, this is to improve the trunk first, clear thinking. This way the code will not look messy and it will be easier for you to clean up.

After the trunk is written, implement the method you encapsulate, which is to fill in the details.

Of course there are people who write it all in a pile and then refactor it, but I think refactoring is refactoring, not in the same direction as this coding trick I’m talking about.

The point I’m trying to make is that it’s easier to show clarity when writing code, and it’s easier for you personally not to let details interfere with your thread.

Bubble sort may be too simple, the feeling is not too deep, we can practice in the usual brush, I believe you can experience the benefits of this practice.

The last

Maybe you’ve seen a lot of sharing of learning algorithms, a lot of books, a lot of websites, a lot of courses, and more is not always a good thing.

I personally think that a column, a website, a book, and an algorithm note are enough for back-end programmers like me. Don’t think that this class seems good, the book seems to be a lot of people, I can tell you very responsible, as far as these I mentioned, you have thoroughly learned, you are basically a “god stage” monk.

As well as the algorithm notes mentioned above, the private message “123” can be picked up.


I’m yes, from a little bit to a billion bits. See you next time.