preface

Recently, in the interview of large domestic factories, the frequency of LeetCode examination is more and more high. I also observed that more and more front-end students began to pay attention to the topic of algorithms.

But the algorithm is a very high threshold of things, in the eyes of an algorithm novice, its IQ threshold requirements are very high. Is that what it actually looks like? You won’t after reading this article.

Be patient to see the bottom, there will be heavy dry goods to share with you.

You can’t throw away the marks

You often hear the phrase “swipe leetcode” before an interview. However, before brushing leetcode questions, I think there are some basic points that must be earned, or given points must not be lost.

What are the scoring questions? You know, data structures in college or in your C textbook. You’ve done them, you’ve spent a semester studying them, and it’s easy to forget to pick them up now. For example, sorting algorithms in data structures, search algorithms, and trees. The interview questions are actually narrower than the content of the book. For example, the knowledge about trees may suggest that you use binary trees to solve a problem, or calculate the number of leaf nodes, or calculate the depth of trees. Others are simpler, such as writing the front, middle and back traversal of the binary tree in both recursive and non-recursive ways. Concepts such as balanced binary trees or complete binary trees (at least I haven’t encountered them) will not be covered, let alone concepts such as graphs.

I don’t see a lot of search algorithms, I see a lot of sorting algorithms. The basic algorithms must be mastered: bubble sort, select sort, insert sort, quicksort, merge sort, bucket sort. Learning to write these algorithms is the worst thing, but the best thing is to know how they work and how efficient (i.e., time complexity) they are. For example, when you’re stuck in an interview, you can at least describe how the algorithm works. The reason to know how efficient they are is because the interviewer may ask you to write an algorithm indirectly, for example, writing the most efficient algorithm in time, regardless of spatial efficiency. It’s important to learn how to judge time complexity, which we’ll use later.

When you make sure you’ve got the basics covered. So start practicing for the harder ones (sorry I don’t know what the harder ones are).

Of course, difficult and easy are still relative, maybe these questions are easy for me, but some people are still difficult. But in any case, there are problems that you are good at and have encountered before.

Learning style

1

Many students who are in touch with the force button for the first time do not know much about the method of brushing questions. Some follow the question number and some follow the daily question. However, this aimless method of brushing questions will usually give up one day in the middle, or brush for a long time but find no sediment. Instead of being repetitive, I will directly point out a method recommended by all the big guys: divide your learning stages into several periods to brush questions of different categories. For example, the first week is dedicated to solving linked list questions, and the second week is dedicated to solving binary tree questions. In this way, your knowledge will form a system, through a period of deliberate practice to strengthen the knowledge points related to the question into your mind, not easy to forget.

2. Give up

Many students have to dig into a problem for two hours. Finally frustrated, over time may give up the algorithm road. To know that the algorithm is a precipitation of decades of field, the solution of an algorithm may be some professors for many years of effort, you want to rely on their own a novice to come up with the same excellent solution, is not too much. Therefore, it is necessary to learn to give up properly. Generally speaking, students who brush questions purposefully will give up and look at the solution of the question within 10 minutes if they have no clue about a new topic, and then write it down and review it repeatedly until the solution becomes their own knowledge. This is the most efficient way to learn.

3. Accept that you’re new

Yes, to put it mildly, accept the fact that you’re not a genius. You will encounter a lot of trouble when you brush the questions. For example, you have seen examples of the same type of questions, but you cannot solve them if you change the conditions slightly. Or don’t have a clue about an easy problem. Believe me, this is normal. It doesn’t mean you’re not good at learning algorithms. It just means that algorithms are a broad and profound field.

If you lack of learning materials now, I do not know where to start, I just from a friend that collected to a “2021 latest version of data structure and algorithm interview question manual”, hard to bite all finished, do not directly see the answer, first their own thinking, or it is easy to forget, really will not see the problem solution, look at other people’s solution method. Then summarize the ideas and common patterns.

1. The hash

  • How does HashMap in Java work?
  • What is a Hashmap?
  • Let me tell you how to construct a consistent hash algorithm.
  • Why are the hashCode() and equals() methods important?

2. The binary tree

  • Find the maximum depth of a binary tree
  • Find the minimum depth of a binary tree
  • Find the number of nodes in a binary tree
  • Find the number of leaf nodes in a binary tree
  • Find the number of KTH layer nodes in the binary tree
  • Check whether a binary tree is a balanced binary tree
  • Determine whether a binary tree is a complete binary tree
  • Are two binary trees exactly the same
  • Flip binary tree or mirror binary tree
  • Whether two binary trees are mirror images of each other
  • Find the lowest common ancestor node of two binary trees

3. The linked list

  • What are the disadvantages of a bucket if it is stored in a linked list?
  • If I have a linked list with odd digits ascending and even digits descending, how do I change the list to ascending?
  • How to reverse a singly linked list
  • Now I have a one-way linked list. How can I tell if there are rings in the list
  • Replication of random linked lists

An array of 4.

  • Write an algorithm that rotates a two-dimensional array 90 degrees clockwise.
  • An array where everything is equal to each other except one element. What element?
  • Find a pair of combinations neutralized by S, just find one
  • Find the maximum sum of continuous subvectors in an array
  • Find the first K largest numbers in an array

5. The sorting

  • Write a bubble sort in Java?
  • So, what are the different kinds of sorting methods? Please list them
  • So, what does merge sort do?
  • So what’s heap sort?
  • How do you get a median in a data stream
  • What sort algorithms do you know, what is the time complexity of each algorithm, explain quicksort?

6. The heap and stack

  • Please explain the usage of stack, heap and static area in memory.
  • What’s the difference between heap and stack?
  • The smallest number of k
  • Maximum sliding window
  • Ugly number before
  • The first K high frequency elements
  • Valid parentheses
  • Minimum stack
  • The largest rectangle in a bar chart

Advanced algorithms

  • Can you explain the implementation principle of LRU algorithm?
  • Why design postfix expressions and what are the benefits?
  • Would you please design an algorithm to compress a URL?
  • Id global unique and increment, how to implement?
  • The length of the last word

8. Dynamic planning

  • Fibonacci number
  • Different paths
  • Climb the stairs
  • Change change
  • Al shabaab
  • Edit distance

Want to learn front-end Web and need PDF document friends can join this penguin skirt, front: 938,, middle: 051,, and finally: 673, skirt from students to big guys have, resources free to share, be there or be square oh!Copy the code