Hello everyone, my name is Zheng Axuan. In this video today, I will share my journey of writing LeetCode and the methods I used. That’s because I believe that many people, like me, feel very painful in the process of writing LeetCode . I’m at a loss, so I’d also like to know how to turn from a novice programmer into a LeetCode master , right? This video won’t mention it at all, because I don’t write the LeetCode questions very well. Then this video It is divided into three parts in total. The first part is my own process of brushing LeetCode. That is, when I came out of the Information Policy Council in 2016, I had not written at all .
I had not learned algorithms and data structures at all. So what is this? Under such circumstances , I rushed in and wrote LeetCode for him . I often wrote some programs with TLE, which is time limit exceeded. Later, I accepted my fate and took courses on data structure and algorithm . So far, I have solved a total of 222 questions. Among the questions, there are 86 easy questions, 117 questions medium, and 19 questions hard . Because 7 years is actually quite a long time, I spent about 4-5 years in the middle without actually practicing, so I divided it into three. Let’s discuss each period. The first one is the beginning period, then the flat period , and the last explosive period . These 200 questions are very interesting. I practiced about fifty questions at the beginning and during the flat period. Then I practiced the next one. More than 150 questions were all written in one go in the last half year or so . The second part is the strategy part , which is about how to brush LeetCode questions more effectively. So here I will discuss it in 4 aspects. Like the first one is the background of the character, because not everyone is like me and came from this job transfer. Some people may be self-taught , some may have a salary background , and those who are currently students , I will focus on these. Different roles put forward some of my opinions. The second one is the four stages. In the process of learning to write LeetCode, my own observation can be summarized into these four stages. What needs to be done in each stage is different from the goal of learning. It's so good. The third one is the method of practicing the questions. This definitely doesn't mean that we just give him a question and write it down like this. This is because he still has his own methodology and certain methods that will help you . It can accelerate your learning effect and make your ability to write programs even stronger. The fourth is some of LeetCode's topic selection methods and other supplements I have made for some of the operations above on LeetCode. This is what
I will do in a large amount later. I only heard about it from my friends when I was practicing. If I had known it earlier , maybe I could have saved some time on the wrong path. The third one is this collection of learning resources and sharing of experiences. Which online courses have I watched ? Because the content of online courses is pretty good. I haven't read them all , but I have read about 80% to 90%. There are some contents that I think are particularly important. If you don't have time , maybe you can just focus on these first. Finally, this is the experience sharing. You may want to say, hey, is this practice test really helpful? Then how far should I practice before I think I can go for the interview ? Then
I will also share my experience with you here , so we Without further ado, let’s start. Wait a minute . If you haven’t subscribed or clicked on share, please help me do it. Or if you find it helpful after reading it, give me a like . It’s a small step for you. I found it right. The influence of my channel is so great. It scares me . It scares me. Well, let’s start. The good time came to January 2016. At that time, I was probably at the level of just coming out of the Information Policy Council. Basically, I should learn We are already familiar with front-end, back-end , database data analysis , and some simple cloud concepts , but the algorithm and data structure are basically completely untouched, right? Because
you see all the imitation training. I don’t know how to teach these things in class , because they are not immediately needed for work , so I start working anyway. During working hours , I often listen to some seniors or friends share and say, wow, this writing LeetCode seems very useful. It seems like it’s fun . The better you write, the higher your salary will be, right? I think writing LeetCode seems to be a sky arena for every engineer. It’s very similar to the one in The Hunter. The tower of the competition is the same. You just have to go in and slowly start to climb up to accumulate your own strength. Because more directly, usually a company will ask this kind of online coding question during the interview , so you Whether you have practiced LeetCode or not will depend on the comparison of the pros and cons between you and other competitors during the interview process. So at that time, I didn’t have any direction or any concept and just rushed in for him to do the blind test, that is, I didn’t know the situation at all. Anyway, it doesn’t matter if it depends on your own strength , right? So let’s take a look at the results
at that time . At that time, the first question I wrote was the 292 question nim game. Why is this place interesting ? Yes , it took me a while and five minutes to write it out . So this looks like what it is. This is LeetCode, which children play with. The second question is 258 AT digits . It is also an easy question , but oh you It looks like it’s not difficult after I wrote it down. It’s okay . It took me 15 minutes to write out this question. The two questions are easy. OK. OK . Here comes the third question . Pull two in a row. 202 happy number. OK . I read the description of this topic and then I thought about it . It took me 90 minutes to write it, which is 1.5 hours before I wrote it . Haha, I immediately changed from the chosen one to the chosen idiot. I don’t think this is very simple. Ah, how could this happen? It’s all easy! Everyone is easy. Why is this so not easy? Damn it! In short, I wrote several questions one after another while working. If you have time, practice it and finally find that on average, this easy question takes about 30 minutes to write . Your execution time is sometimes good and sometimes bad. Sometimes it is good and it runs out in about 60MS. The worst one is There is also a state where it only took 1889MS to write. Oh, what is this execution time? It means that after your program is written, LeetCode will run a section of their test code to detect how much it will cost to run all the tests of your function like this . Time : The better the performance of your program, basically the shorter your running time will be. So it can be used to evaluate whether the performance of your program is good or not. Well, let’s take a look at this 1889MS . It’s me. This is the number one question in the world, two sum two sum. Let me show you the program I wrote at that time. Oh wow, this two sum. Here are nums, pre_numes life filter . As you can see , it should actually be a double for loop. So I know the concept and write this. This is what we commonly call waste code. It looks like a double loop , so its performance is O(n^2). This
program you wrote like this during the interview should basically be able to do it. I was asked to go home directly, so I basically stepped out of the novice village at the beginning. I could only write easy but could not write the longest question on medium . I could write for about 90 minutes , let alone the interview . Look, I don’t even have the courage to throw away my resume. It’s 2018. After two years of writing, if you have a good job, you will start to develop some sense of writing programs. Let me show it to you. I will write this later. This two sum has an execution time of about 125MS, so it is considered passable. Let me take a look at its solution. You can see that it only needs one map , and if it exists, push it to mine. This outList has only one map when it is finished , so it basically has an execution time of O(n) . After working for two years, I can basically write easy. Here, this easy is all 5 -It can be done in 10 minutes. I can also write out the medium part a little bit , such as the nth digit of 400 and 540 single element in a sorted array , but it can be written , but it takes me a lot of time . It takes me 25 minutes to write each medium question , but not every question is so smooth. That’s because I refer to some classic questions that others have said , such as this question 5 longest palindromic substring . For this question, basically I I can't write it down at all. I ca n't write it down at all. Let me show you this cruel record. Is there a wrong answer? Time limit exceeded. Oh, this is terrible. blah blah blah. So you can see that it was almost done. It's not good enough. Haha, in short, this situation is that there is no one to practice until 2019 before entering the next round. In 2019, I started to give myself the so-called new year and new hope. The reason is because at this time, Easy has actually written medium. I can almost write these questions. Although it takes about 25 minutes to write, I think I can write them all by then. I shouldn’t have to spend time looking at algorithms and data structures. This thing is so boring , so I am very In my arrogance, I decided to set a goal for myself , which was to challenge myself to write hard questions. At that time, it was basically easy for me to write medium questions. I could also write medium questions. The average time for each medium question was about 25 minutes. So overall, I I have written almost 20 questions, so I should be able to try something new and difficult. As for which question to write on Hard? Anyway, there are so many Hard questions , so I just randomly selected a question for it, and I happened to encounter this question 354. Russian doll envelopes, it should be pronounced like this. I don’t know. Let’s take a look at the question. What is this question for? It means that it will give you an array of envelopes. It is a too dimension array. So what does it represent about this Russian doll ? Width and length, and then what about every Russian doll? Because what he has to follow is that the small one is wrapped inside the middle one, and the middle one is wrapped inside the big one. So one by one , it is wrapped into the larger length and width, so it is I asked you to write a function or an algorithm to help me calculate it. I mean that among the set of Russian dolls I gave you, it is the longest. How many Russian dolls can be included in it ? Like this example, it can be calculated by taking four of them and calculating the maximum. The number is 3, because it can jump to 5 after 2, 3, 5 , 4, or 6 or 7. If you are one and one, then you can only wrap one because the length and width of your next one will be larger than the previous one, so it can be like this. You can't go down if you don't have a bag, so if you think about it intuitively, it's a bit like path selection. The problem of path selection is that the length and width of each next node you jump to should be larger than the previous one . I hope that the node path that comes out like this can be the longest. Dear brave warriors, if you see this question now, welcome to challenge this 354-question Russian doll envelopes. Let me tell you, this powerful person is not fake. After I read and thought about this question at that time, I wrote it in 15 minutes . It’s no exaggeration. It really took 15 minutes. Of course it’s impossible to fake it . Hahaha, no. That day, I remember that the goal I set for myself was to finish the New Year. Or the first week or something, and then I will have one morning and one afternoon. It’s really not an exaggeration. At 9 o’clock in the morning, my alarm clock rings at 8:57. On holidays, I get up at 9 o’clock and have breakfast. At 9:30, I stay with us. Home's Home's The door of my room was facing the door of my room and I started writing. I started reading the questions. I took out my paper, took out my pen, took out my ability to teach mathematics before, and wrote and wrote and wrote all morning . I want to say, oh, the morning has passed. Hey, it’s okay . Hard. You have to respect the difficulty of Hard questions. OK, OK. It’s OK all morning. By 5 o’clock in the afternoon, I still haven’t written it. I think I thought about it for almost 9 hours. Hey, it shouldn’t be 9. I should have been unable to write it all for 8 hours . Sure enough, I thought about many methods and then tried to think about it from a mathematical perspective , but in the end I got this wrong answer. Let me show it to you. This is what the program I wrote when I was 19 years old probably looks like . This is probably my ability to write programs for about 3 years. Let me show you what the program I wrote after about 3 years looks like. Oh, Max envelope , wild truth hmm uh. huh create pass okay uh gentry option flats and ever salting okay so if I were the interviewer I would say hey can you please explain what exactly you are doing when you write this program. Now that I look at this program I will think he is A program written by a person who has never studied algorithms or data structures is right. Why I will explain this later. Anyway, I was very ambitious but also very timid that year. It just took me a day. I wrote a hard question in the time and couldn’t finish it, so I gave up. I didn’t dare to challenge other hard questions because I thought it was so difficult. I couldn’t understand what everyone thought . Hahahaha . So this stage is about losing to these Russians. This round of the Stinky Baby situation ended. At this time in 2021 , I have been working for 5 years . In 2021, the new coronavirus pneumonia has been in the past five years. In fact, I was last hit in about 19-20 years. After that, I never practiced again . I never practiced anymore. Let me show you my commit. I never practiced anymore. As for writing time every day, I was actually learning other things. I just looked around and then I also tried to teach and started to cooperate with some schools. Then I went to this training unit to teach. In addition, I also taught at the Vocational Training Bureau. Then I also tried to record YouTube. At that time, my channel was called Jeff Ga Program. My classmate felt very embarrassed after watching it. Well, I also felt very embarrassed. You asked me why I didn’t practice LeetCode . In fact, I think the most critical point is because you didn’t use it at work. There should be many people like me, that is, if You are writing some application-type web and API-type things. In fact, in LeetCode, it should be said that algorithms and data structures are not such a priority, and other immediate capabilities that may be used in other work are needed. You need to learn first, for example , the planning of the DB schema we are talking about , and how do you deploy your service to the cloud directly like GCP or AWS? After deploying it directly to the cloud, you need to be a monitor , that is, you have to check to make sure that the service is not If something is broken and there is a bug, you need to have a log to analyze it. Then, if it is broken, you need to have a backup mechanism. This is the design of disaster recovery that we talked about. In 19 years, I did it myself. I took the GCP Cloud Architect Certificate , which is the GCP Professional Architect Certificate. My friend took the AWS GCP related certificate, so I was stimulated by him to take the exam. Then, after finishing the exam, I was very arrogant . I often ask my colleagues what's going on. Do you have any professional questions that you want to ask me? My colleagues say no , I just want to ask you what you want for lunch. Anyway, you can know that there must be other things that are more important at work. I wanted to learn , so during that time, the so-called LeetCode practice, algorithm data structure, bobobo, was put in a relatively late place. As for why I came back later and started wanting to practice this, the biggest key is because of the new year and new hope of 2021. In this new year, everyone likes to make wishes, but everyone may not be able to do it, and I can't do it. It doesn't matter. At that time, the goal I set for myself was to write at least one hard question to answer at least one hard question to answer the question. In 19 and 20 years, there were other things to learn, so I just finished practicing . By 21 years, my work had entered a stable period. There was nothing in particular that I needed to practice or want to learn, so I decided to put this in my list. The second more important thing in this training menu is because I have the impression that I lost to that damn Russian doll last time , so I will always remember this, and I thought, wow, I lost, so I put it there. I have always felt very awkward and thought that I must come back to deal with that thing one day, so it will start in March 2021. But the question is, if you want to practice well, which question should you practice ? At that
time, my friend had other My friends happened to coincide with each other. What a coincidence. I wonder if someone shared this secretly. They happened to encounter a question during the interview , which was question 51 N-Queens . Let me show you this question 51 N-Queens. This question is calculus. It's a classic question of law . I don't know what to write. I must practice this question. Please, everyone, let me take a look at what N-Queens is. If you have friends who have played chess, you should know the move of this Queen. The cross also has the oblique angle of the octagon, so it is equivalent to an all-round chess piece. The question of N-Queens means that he will give you an n by n chessboard . Then we have n queens to put on it. Go up to this chessboard. Could you please write an algorithm so that these n queens can be placed on the chessboard without blocking each other's paths ? What do you mean? Then take a look at this example. If I set n=4 today, it would be a 4*4 chessboard, that is, 4 Queens. Then look at these 4 Queens. They are placed the same on the left and right, regardless of the horizontal angle. Or move at a right angle or diagonally, you will find that every Queen does not block other people, and there is no other person on its path. It is a good way to put it right like this. The left side is a right side, and it is also a pair. So Your algorithm needs to be able to help me calculate the combination of this placement method. For the chess piece, use q to represent it. For the other pieces without chess pieces, use a dot to represent the return. That ’s it. So my n is equal to 4 and the output is It will be these two solutions. If n is equal to one, it is equivalent to the chess method of one square, so just put a queen. If n is equal to 5 and n is equal to 6, you can analogize it in the same way. If you want to put 6 queens on a 6x6 chessboard, then n equals 8. If you want to put 8 queens on an 8x8 chessboard, please tell me how to write this question. I will tell you first. If you haven’t learned the algorithm after watching the video, you can give it a try. Because that's what I did back then. I didn't learn any algorithms. I just rushed in and tried it with her. There is also a supplement. Because I think he has a little bit of mathematical concept for this question . You can see example 1 for everyone. A little tip is, do you think it looks like a symmetrical answer or a symmetrical solution ? I had the idea at the time that maybe after I catch one answer, I can piece together the other answers using symmetry and rotation , so in this way I started writing and started writing questions like crazy. At this time, I didn’t write in the morning. I couldn’t come up with writing in the morning , so I gave myself a time to start writing at 4 pm . I remember the state at that time. I had already been working for five days. I also got a GCP cloud architect certificate in 2021. Although it is said to have expired in 2021 , and I have also written a lot of systems , I should be very confident and proud at this time , right? Anyway, I am at 4 o'clock I sat down and started thinking about how to write this question , and then I drew a lot of pictures , and then I wrote while matching dinner like this. At 9:12, I successfully handed over a level-solving program that took me about 5 hours to write. After another 12 minutes , I finally wrote out this question , so I can show you what the program I wrote back then looks like. Let’s take a look. First, he first dealt with n equals one, n equals 2 equals 3 , and then hey, this I don’t seem to know what it is doing. Anyway, I seem to have done some sorting, then d1 , haha, and then Dynamic get next point , haha. So I wrote a function like this and then getSpacePoint, which should be below. It failed completely . Just return false. , good getSpacePoint , um, um , it seems good. Occupy, I think about it, I seem to calculate it one by one. Then when it reaches a certain grid, when it is placed, I have to remove all its crosses and slashes. I remember the cross is like this, i equals 0, i equals 234567, wow, it’s awesome, okay, I think it’s pretty strong, haha . I successfully solved this n Queen in an unknown situation, so at that time I My friend told me that he was taking these questions in an interview, and I thought to myself, "Oh, I should be able to take the exam too." Although it seemed that it took me about 5 hours to write it out , yes, so my mentality at that time was actually quite proud of me. I think I have the ability to write hard questions by myself in an unknown situation , so my own practice process is OK and good. But after practicing, I have to do one thing reluctantly . Look at solution. There is a tab on this LeetCode called solution . Many people will post their own solutions . It is recommended by many people because looking at some things for too long can lead to obsession. People start doing some methods to show off their skills . After I read so much, I began to understand what they were doing because I had never heard of many terms and concepts. I won’t talk about this concept because I’m afraid it will explode, so some people may want to practice it by themselves, so I Let’s not mention what concept he used. In short, after chewing on these solutions, I wrote it again. I used the concept mentioned by others and the same method. I folded the cards myself, folded the cards, and then wrote it again. Okay. Let me show you what this program written by someone else looks like. You see, he wrote a soft and Queen, and then executed a main program, called placeQueen. Good placeQueen. In it, it's like bum bum bum bum. Then one, two, and finally this. parsingResult was written by myself. I remember that at that time , there were only two functions, placeQueen and isPlacedValid . I don’t know how you feel after reading this . Think about it . If you are an engineer who is interviewing others today , you just read it. The code I wrote is also another set of code you wrote after reading the algorithm . That includes its execution time. My execution time is 220MS and his is 90MS. In this case, if you are the interviewer Who do you want to invite for the second round of physical interviews ? It goes without saying. I think the answer is quite obvious. For me, after reading and writing, the sense of accomplishment and pride that I originally wrote was gone. At that time, I only had one idea in
my mind - a few thoughts, such as the fact that I had written so many and could not compare to the short few lines of programs written by others. The second thing was that after I read it, I suddenly realized that others I talked about what is a frog in a well. Is it possible that the algorithm will be very poor on these hard questions? Many digressions here also happen to integrate one of my previous opinions. Oh, I am from a job transfer background. I am not a staff major. I don’t know if everyone has the same idea. That is, when we meet people from a purely salary background at work, psychologically speaking, we will feel... A little dwarf and a little bit I call it my own inner demon , which is the inner demon faced by salaried people. So
when I wrote this algorithm, I actually had the same thought when I looked at these two solutions. I feel that after working for so long, I still seem to be losing so many pairs to others, so I finally made an inference for myself. This inference is that the set of things I originally worked with is no longer enough. Use it and it can accompany me in my work. I may have 5 or 6 years of experience now , but if I want to move up or if I want to go to the outside world to challenge more difficult things, maybe I need to use some new methods to learn some new knowledge, so it is time. Come to learn data structures and algorithms for yourself. But actually in 2019 and 20, it was the time when I said it was relatively confusing. In fact, when I was bored, I also read articles about these algorithms and data structures, or this Technology sharing or online courses, but I believe that many people think the same as me, that it is really boring. When the teacher is in class, he will start to say, oh, let’s solve this problem next , and then directly think about this , and then we will write Some pseudo code and then writing some proofs , but this data structure and algorithm are also very interesting. Every time I meet someone for an interview, I often ask them what are your future plans. Everyone will want to put this in and say what they expect in the future. I learned this data structure and algorithm. Junior’s part is right, but I’m still half-convinced as to whether he’s done it or not , because based on my own life experience, I’m half-convinced . And the second thing is that at work, it’s really what I’m talking about , but it’s not that immediacy. Because I write some B2B business systems, I may not have encountered problems that need to be solved with a big knife like algorithms . So in 1920, I practiced slowly, looked at it slowly, and then turned it off quickly. I went to watch something else and watched Attack on Titan , but I thought that if I go for an interview in the future, I might still encounter some medium or hard questions. You can’t be as hard as before. It takes five or six hours to write each question before handing it in. This feeling must be It will be brushed off, so my new hope for the New Year in 2021 was to write at least one Hard question. Unexpectedly, I have already done it by accident, so I will add two more things to myself. I start from the frog in the well. This is a mentality. For self-identification , I first realize that my own strength is not enough , and then I hope to finish learning algorithms and data structures in the next time, and then write at least 5 Hard questions. The question is where do you want to learn the fastest at this time ? The best method is how to look at PTT , so I opened Google and then keyed the data structure algorithm PTT recommendation, then looked through all the product recommendations , searched them again , and then actually looked at the teacher's style . Finally, I chose Yangjiao University. I’ll put this in the open course at the back of the learning resources and experience sharing , and then introduce it to you. This is what I think. I watched it myself. I think it’s the most interesting and the one that talks the best seems to be the best. The lectures are pretty good, the lectures are very good, and the lectures are very good. Quickly mention what things I have learned. For example, when I studied algorithms, I watched bigO, binary search greedy, divide & conquer, DP DFS and BFS. Now let ’s go to the data structure part and look at the linking list tree hash map, stack, and Queue . There are many more details that I didn’t see. After looking at the learning resources, I have to say that I think this process is actually unexpected. I was surprised. I think it's quite interesting, like dynamic programming, and I like it very much because I think his thinking is something that I have basically never touched before when writing . Wow, this new field is so cool, and I think it's fun to write about it. Some of them are really boring, like what to prove, to prove , to prove. I also felt very bored, but I still followed the writing and fell asleep after finishing it. After writing, you started to talk, play, and read. Is this meaningful? Ah, the teacher is teaching recursive. Recursive is calling yourself repeatedly. Is it meaningful to think about this ? Is there any meaning to this? Thinking about it, it will become like this. I feel mentally tortured . In short,
I spent about half a year. Time has taken me to look at the data structure and the algorithm part , so half a year is too late to read it. In fact , I just have to look at it very carefully. Well , I spent about two to three times a week looking at it. I was single at the time, so I had nothing to do. I had no choice but to start seriously studying the data structure and algorithm. Anyway, after reading it and watching it, I can only use four words to describe my own skill. It’s like that who ? Guo Jing may have met Hong Qi while walking on the road. The gentleman also gave him a secret book of the Eighteen Dragon Subduing Palms. After it came out, he was so scared that his power increased greatly. After that, you want to start looking for people to be sacrifices. If you see anyone, come and give him a try right away. For me I said that I would try some medium questions first because the hard ones were a bit too difficult and I didn’t think I could write well, so I tried the medium questions and I still couldn’t write them, hahaha. For
me at that time, I remember I tried it. Two questions, I may not be able to find them , but it doesn’t matter. Anyway, I wrote a few questions and found that I still couldn’t write well. But I think this is normal, because this requires more practice. I think this is something you will definitely encounter in science subjects. The state is so terrible . By September 2021, after practicing for half a year, I observed myself and found that one thing started to be different. What's the matter? I seem to be more handsome, and I feel more confident. No, no, no, no, no, no, no, no, no, no, no, no, no, no, no, no, this is what I found when I was thinking about the topic, I started to have two kinds of thinking. The first thinking is about myself . When thinking about programming, when you see the question, you may want to use objects, arrays, and then loops and functions to think about how to solve this problem. You may sort first and then write a map . The second kind of thinking is The so-called algorithmic thinking. When I see a question, I will try to think about whether things like DP DFS BFS or sliding window two pointer that the teacher teaches in class can be used on the question. If I use this method to solve it Is there a way to solve the problem ? I call it algorithmic thinking, which means that in addition to using the general logic of thinking about programs, you also try to think about the algorithm you have learned. Can this problem be solved ? Then I think this is very interesting. This seems to be more like the starting point of my thinking from not being able to write programs to knowing how to use algorithms to solve problems. Yes, so I try to use it every time. Every question is written in this way. I want to say whether I can use an algorithm I have learned to solve this problem , and then train myself to force myself to use this kind of thinking to write this question. I will be very lucky. Oh, this was the fifth question that I couldn't write in 2018 and 2019. I couldn't pronounce the Longest Palindromic Substring . Later , I knew I had to use algorithmic problems to solve it . I once used the DP method to solve it , but the performance was very poor. It seemed to be O(n^2). So later I looked at this solution and chose another method to solve it . Then I won’t explain it for fear of everyone. Explosive . If you are interested, please read on . So after I established this algorithmic thinking, I still had no solution when I encountered each question. I just saw the question and said, "Sanxiao , that's the one I looked at." The third primary school is always the same. I watched the third primary school , so I later found out that it didn’t work, so I adopted the second strategy. The second method is to use tags to lock the range. There will be something with this tag on LeetCode, and it can be locked . It depends on you. Which type of questions do you want to solve first ? In mathematics, if we don’t have probabilities of permutations and combinations of trigonometric functions or pairs of vectors , then I prefer trigonometric functions. I might want to write down questions about trigonometric functions first . I think it’s a program. My favorite algorithm is DP, which is Dynamic programming. When I was practicing, I unexpectedly learned a lot of things . During class, I heard the difference between bottom up and top down. Well , I understand the concept, but I understand the specifics. Speaking of program differences, I only found out when I was writing that there is also binary search. People often say linear search and binary search. This difference is very interesting. There is one called monotonic stack. I didn't see it in class , and then I was writing it. I only encountered this question when I was asked about LeetCode, and I actually encountered this during the interview later. I thought it was very mysterious, and it was so difficult. So from September to November, I basically just looked at this calculation for the first half of the year. I tried to find ways to apply the method and data structure to this LeetCode, and
these thoughts were really established by me. So in November, I went back to face the problem that I couldn't write at that time. The topic was that damn smelly doll, Russian doll envelopes. At this time, I basically had this algorithmic thinking. So when I came back to look at it later that year, I immediately knew that it was a topic related to DP , and I was not the only one who saw it right away. I saw that the mark below also said dynamic programming. That's great. Anyway, I wrote it when I had this kind of thinking . The first person to write fancy words wrote it in. The result was wrong . Don't be nervous. I must be too proud, so I Oh, I must not have considered the boundary condition. I should write this thing again. It’s wrong.
It must be because I was too excited. I took a look at it. Oh , I forgot to add this initial condition. So I added it again . It’s wrong . I don’t believe it. I feel that the stinky baby looks down on me. I didn't write it again and finally I corrected it. Although
, let's take a look at its execution time. It's 1328MS. Oh, this is not a very good result . You can see that this beats 5.45% is basically you. The PR5 is the last five people among the 100, so I think this answer is a bit difficult to accept and I have to change it. Anyway, I have corrected it again and again and again and again, and finally I fixed it to 700MS. Although 700MS, It's still PR5 or 5.45% , but I think it's already some progress. Have you finally passed it? Fortunately, in the case of finally passing it , in fact, I just talked about the very intense process. I spent a lot of time on this Hard question. It took me 25 minutes to write it. Compared with a few years ago, when I spent 5 hours writing this question and couldn't do anything, I finished the paper in 25 minutes . PR5 Wow , this is the SOP. After reading it, I read the detailed explanation and then read the detailed explanation. Damn it, it was so well written. I was amazed. So I followed the detailed explanation and revised it again. Finally, I wrote a performance like this. 252ms, O(nlogn) solution. This is very interesting. Although the school is in class Or the algorithm and data structure are taught in online classes, which is one thing , but when you actually look at these solutions, you will find that those geniuses are really geniuses. I don’t know how they came up with these things. I know it's awesome, but let's compare it to why I said last time that the program I wrote in the early days looked like a program written by someone who had never studied algorithms and data structures. The bigger point is actually you. The core thinking of this algorithm is what kind of algorithm you use to solve this problem. The concept of algorithm is that it is actually a comprehensive solution . When you encounter a certain problem, maybe we can use this Methods to solve it. For many practical problems or many such programming problems , you will find that they are all asking about similar concepts. So what DP solutions can we use when encountering this concept? When we encounter this concept b, we use DFS. The solution will roughly look like this . Yes, so when I read it at that time, I didn’t have the concept of this algorithm in the early days. I could only use my little brain to come up with some solutions. OK, how to do it first , and then what path will it be judged on? After scanning the data , if there is a match, do b. If not, do c. In fact, the whole structure will be very different. It ’s messy. If you have learned the algorithm today , when you see the problem today, you can first figure out a general direction and say whether I should use DP DFS or use a solution like two point to solve it . After we know the specific direction, we will look at how to divide it into actions to implement it. If we look at the solution for a Russian doll like me, I know that I have to use DP to solve it. Then when I solve it, I may have to First do sort to sort these things, and then use DFS to scan them in one by one. During the scanning process, I need to compare certain things every time . This is the third action , so I put these three After each action is confirmed, I will start writing the program. This kind of echoes what I talked about before, the so-called 70% thinking concept, that is , we must first think about how you want to solve it. Let’s start with the actual coding thing. So have you ever learned algorithms? When you encounter a deep-water problem, it will be immediately obvious that it is a solution with a main axis. Start working towards this main axis solution and slowly put it into practice. When you write it down , it's a bit like uh, I might want to do a, b, or c, and then try to see if I can make it. But if I ask you to tell me what algorithm you use , you can't tell me. Come out. In short,
it means a lot to me to solve this problem because I read the New Year's New Hope for 2021, the data structure and the algorithm , and wrote at least 5 questions at the same time. It’s a rare thing to do. From then on, I officially entered the explosive period of my LeetCode practice. I often start writing questions crazily two months before the interview . At that time, I wrote almost 80+ questions in one month. The questions came out. At
that time, I already had algorithmic thinking , so I had basically written some medium or hard questions. I
want you to take a look at my LeetCode commit record. You can see it and tell me. I started practicing crazily from about August to November . This is also related to finding a job. I think, and then in May and June of 2022, I will also be writing crazily . Then it will be like this. This four to five month period is just a short period of time. I wrote a total of 150 questions in the first few months. If the average performance is medium, it can be written in 20 minutes. If it is hard, the longest time is about 40 minutes, and the average is about 30 minutes . Easy is The thing about writing about relaxation is that you can watch TV and chat with others and then write . Sometimes when your head is very tired, you can write about it to relax yourself and adjust your body and mind . If there are people who follow my IG, they should have found out except for me . Share some strange posts that I created by myself. What about Junior interviews, process and thread ghost stories, etc. Occasionally, I will share this interview question on a limited basis. Once when I was interviewing, I encountered a question, and what is the process? The other party first sent the online test questions of this system . Then I might register and log in. Then he will have a time limit. Then within two hours, you have to finish writing these three questions . I will wait until I finish writing them myself and evaluate them. I think it is medium medium hard doesn't say which type it is, but this is how I observed it myself. After I finished writing, I added some comments about what I wanted to do . I introduced my logic and my focus on things like time and space. The complexity analysis shows that it took about 100 minutes to finish writing it all . There are still 20 minutes left , or 120. In fact, I kind of forgot. Anyway, I finished it within the time and handed it in. The hunter will notify me a week later. I said my writing was pretty good, so I got into the 2nd interview smoothly. But then because I got another offer , I didn’t go on to the interview. I later shared this test question , but I also packaged the question a little to protect it. Respect the company's right to take exams. I think that if I hadn't written these algorithms, I would definitely not have passed the exam and interview. This was my mentality at the time . Some friends would share that if you want to join a company like Tamama, Oh not that Tamama It's from the technology unicorn, these 6 Tamamas. If you want to get in, you may have to answer these questions until it becomes a gut reaction during the exam . Oh, yes, because I have never lost these resumes, I also I have never been interviewed. If anyone wants to share, you are welcome to leave a message below. I, I, I, I also want to know. In short , I only start to do a lot of test questions before the interview when my hands are itchy. Because it has been a long time. Practice , so you will definitely become rusty. But if you have climbed up like this, that is, the stage I just talked about: it starts out flat and then bursts into writing a lot of questions. Then I think the speed of the recovery of this hand feeling is very fast. Maybe I can write a 3- 5 questions, you will get started immediately and you can continue to prepare for your interview. Okay, the above is my mental journey and experience from the first question to the 222nd question of LeetCode. You can see that in fact I didn’t take it very seriously, and there were a lot of blanks during the practice . But what is certain is that these things were accumulated with my blood, tears, and time . So I can assure you that there are no shortcuts to these things and I can only practice them slowly.