This year I had another wave of interviews and collected offers from FANMG, and found that the proportion of answering questions in job hunting was getting lower and lower. There are many reasons for this, but the biggest factor is that it is not that difficult for me to solve the questions.
Looking back, I can see that brushing up on the questions is once and for all. After you get through it, the rewards will be continuous. After completing a complete and systematic brushing on the questions, you only need a little refresher when looking for a job. Moreover, as the level gets higher and higher, the proportion of algorithm questions becomes lower and lower, and more is tested on systematic knowledge, leadership and culture fit.
I did some sharing recently and found that many people are still suffering from answering questions and are even a little confused. Here I will sort out my method of answering questions and hope it will be helpful to everyone.
Several key points
- You only need 200-300 questions to answer questions. Quantity is not the key to success. Increasing the number will overdraw your energy (of course, if you are energetic, feel free to answer questions).
- You don't need to be able to write down the answers to pass the interview. You need to understand why this solution is used and the trade off between the various solutions. If you can communicate well before writing the code, it can greatly give you extra points.
- Don't think that the test questions are difficult. Compared with the college entrance examination, it is all child's play, and there are only a few core algorithms and so many solutions. If you understand each solution thoroughly, you will not encounter anything too outrageous.
- DP is not within the scope of today’s discussion. You can take a look at the common ones. Unless you are looking for a specific company, otherwise DP is a waste of youth.
- Interviews depend on fate. Don’t be afraid of being asked a question you don’t know, so you just want to answer all the strange questions. Most interview questions are common and the interviewer is also a human being. He just wants to test your ability. Being too difficult is not conducive to testing or recruitment. Of course, companies that are not afraid of not being able to recruit people are excepted. If you are really asked and you don’t know, just try your best to do it. This is fate. In other words, sometimes even if you answer well, you will be rejected. Don’t take it too seriously. Everything will happen when fate comes.
- System design and BQ are not part of this discussion
Question brushing method
I follow the steps below every time I answer a question. If it is my first time to answer a question, I need to spend more time understanding each question instead of just solving it. The timeline is about 1 month, usually 3 months if it's your first time. It is not recommended to schedule it for more than 3 months. Firstly, it will consume your energy. Secondly, if you are not focused enough on each question, it will not give you a deep understanding.
- Review of basic knowledge: This aspect basically means looking at the advantages and disadvantages, time complexity, and applicable scenarios of various algorithms. You can organize this yourself and use it every time.
- Answer the questions according to the solutions and question types (the question types are sorted at the back), and mark those that you feel unsure about (not fully understood). Advance this section according to your own ability. Remember to fully understand before moving on to the next one, otherwise it will be in vain. In addition to the questions I listed, you can brush up on the high frequency of the question type according to the tag on the right on leetcode to make sure you understand it thoroughly.
- Check for gaps and fill in the gaps. Take out the previously marked questions and mix them up.
- [After submitting your resume] Start checking frequently according to the interview experience and company tags, while doing the interview. When submitting your resume, sort it into tiers yourself, and submit those you don't want to go to first to practice your skills. If you submitted your resume and received no response, please go here:North American job search (resume modification) consulting services
Question types and solutions organized
Here we just sort out typical question types and solutions for you. How to solve them specifically? You can search the template online by yourself, or leave a message to ask questions. If you are really unclear, the consulting service linked above can be used to answer questions.
Binary Search
This is the most basic, you must memorize it and know when to use it. Basically, there is a sorted array, and then you should think of binary seach when looking for a number. The time complexity of sorting is NLog(n), and the time complexity of searching is Log(n), so it is a solution that is better than O(n) traversal.
Here is a set of templates I use. Note that here I have start + 1 < end, so they are adjacent at the end. You need to check which of the two adjacent ones is the result.
class Solution: def search(self, nums: List[int], target: int) -> int: start = 0 end = len(nums) -1 while start + 1 < end: mid = start + (end-start)//2 if nums[mid] >= target: end = mid if nums[mid] < target: start = mid if nums[start] == target: return start if nums[end] == target: return end return -1
- https://leetcode.com/problems/binary-search/
- https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
- https://leetcode.com/problems/first-bad-version/
- https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size/
- https://leetcode.com/problems/search-in-rotated-sorted-array/
- https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
- https://leetcode.com/problems/search-a-2d-matrix/
- https://leetcode.com/problems/search-a-2d-matrix-ii/
- https://leetcode.com/problems/find-peak-element/
Tree
If you are a novice, the tree question will be more difficult to master, but there are two solutions - Traverse and Divide Conquer. You can understand the difference between the two and lay the foundation for the subsequent DFS. This part of Tree will be more difficult, but it must be mastered.
- https://leetcode.com/problems/binary-tree-inorder-traversal/
- https://leetcode.com/problems/binary-tree-preorder-traversal/
- https://leetcode.com/problems/binary-tree-postorder-traversal/
- https://leetcode.com/problems/maximum-depth-of-binary-tree/
- https://leetcode.com/problems/diameter-of-binary-tree/
- https://leetcode.com/problems/binary-tree-paths/
- https://leetcode.com/problems/maximum-subarray/
- https://leetcode.com/problems/balanced-binary-tree/
- https://leetcode.com/problems/maximum-average-subtree/
- https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
- https://leetcode.com/problems/validate-binary-search-tree/
- https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/
- https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
- https://leetcode.com/problems/binary-search-tree-iterator/
- https://leetcode.com/problems/insert-into-a-binary-search-tree/
- https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
BFS
I think this part is the easiest after the dichotomy. However, the code is relatively long, but it is very enjoyable to write. In many cases, if both BFS and DFS are available, it is recommended to write BFS, which is easy to understand and not easy to make mistakes. Of course, I have also encountered interviewers who must write DFS. After all, BFS is too simple.
I will not provide the BFS template. To put it simply, use a queue, put the initial point in it, and then loop until the queue is empty. Each operation puts the processed nearby nodes into the queue. Remember to use a set to check whether it has been let go, otherwise it will be an endless loop.
**In addition, BFS involves pictures, which are also included here.
- https://leetcode.com/problems/binary-tree-level-order-traversal/
- https://leetcode.com/problems/binary-tree-level-order-traversal-ii/
- https://leetcode.com/problems/serialize-and-deserialize-binary-tree/
- https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/
- https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/
- https://leetcode.com/problems/graph-valid-tree/
- https://leetcode.com/problems/clone-graph/
- https://leetcode.com/problems/number-of-islands/
- https://leetcode.com/problems/number-of-distinct-islands/
- [Although this question is not relevant, it examines the operation]https://leetcode.com/problems/spiral-matrix/
- [It’s better to use DFS]https://leetcode.com/problems/word-ladder/
Topology and graphs
Topological Sort is related to graphs and is extremely high-frequency. Master how to use indegree to find the entrance.
- https://leetcode.com/problems/course-schedule/
- https://leetcode.com/problems/course-schedule-ii/
- https://leetcode.com/problems/sequence-reconstruction/
DFS
Basically, they are looking for permutation or combination questions. It is difficult to get started with DFS, but once you get started, it is a very powerful tool. Unlike DP, you don't know how to use it after learning for a long time.
- https://leetcode.com/problems/combination-sum/
- https://leetcode.com/problems/combination-sum-ii/
- https://leetcode.com/problems/subsets/
- https://leetcode.com/problems/subsets-ii/
- https://leetcode.com/problems/palindrome-partitioning/
- https://leetcode.com/problems/permutations/
- https://leetcode.com/problems/permutations-ii/
- https://leetcode.com/problems/n-queens/
- https://leetcode.com/problems/word-ladder/
Linked List
This concept must be mastered first, otherwise it will be a mess, especially for pointers. If you don't understand it very well, I recommend reading a book first. One of the most important tips for linkedin list is to use dummy node
- https://leetcode.com/problems/partition-list/
- https://leetcode.com/problems/merge-two-sorted-lists/
- https://leetcode.com/problems/reverse-linked-list/
- https://leetcode.com/problems/reverse-linked-list-ii/
- https://leetcode.com/problems/swapping-nodes-in-a-linked-list/
- https://leetcode.com/problems/reorder-list/
- https://leetcode.com/problems/rotate-list/
- https://leetcode.com/problems/copy-list-with-random-pointer/
- [I will definitely not take the exam, but I will learn the skills]https://leetcode.com/problems/linked-list-cycle/
- https://leetcode.com/problems/sort-list/
- https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/
- https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/
- https://leetcode.com/problems/reverse-nodes-in-k-group/
Array
There are many and complex array questions. Some of them can be solved using hashmap/hashset or PriorityQueue. However, it is still recommended to brush up on them when you have time. If you don’t have time, just take a look at the following typical ones.
- https://leetcode.com/problems/implement-strstr/
- [Three-eye flip]https://leetcode.com/problems/rotate-array/
- https://leetcode.com/problems/intersection-of-two-arrays/
- https://leetcode.com/problems/merge-sorted-array/
- https://leetcode.com/problems/median-of-two-sorted-arrays/
- https://leetcode.com/problems/k-closest-points-to-origin/
Prefixes and arrays
- https://leetcode.com/problems/maximum-subarray/
- https://leetcode.com/problems/subarray-sum-equals-k/
double pointer
- https://leetcode.com/problems/move-zeroes/
- https://leetcode.com/problems/remove-duplicates-from-sorted-array/
- https://leetcode.com/problems/valid-palindrome/
- https://leetcode.com/problems/rotate-string/
- [Difference from hashmap solution]https://leetcode.com/problems/two-sum/
- [Essentially 2sum]https://leetcode.com/problems/3sum/
- [Essentially 3sum]https://leetcode.com/problems/4sum/
- https://leetcode.com/problems/3sum-closest/
- https://leetcode.com/problems/sort-colors
Priority Queue
A very powerful and easy-to-master data structure, but you must know how it is implemented (heap)
- https://leetcode.com/problems/ugly-number/
- https://leetcode.com/problems/ugly-number-ii/
- https://leetcode.com/problems/top-k-frequent-elements/
- https://leetcode.com/problems/merge-k-sorted-lists/
- https://leetcode.com/problems/high-five/
- https://leetcode.com/problems/k-closest-points-to-origin/
- https://leetcode.com/problems/merge-k-sorted-lists/
- https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/
other
- A very high-frequency and comprehensive question:https://leetcode.com/problems/lru-cache/
- https://leetcode.com/problems/meeting-rooms-ii/
- https://leetcode.com/problems/insert-interval/
- [Common DP questions]https://leetcode.com/problems/trapping-rain-water/
- [Ultimate DP for buying and selling stocks]https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
- https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/
- https://leetcode.com/problems/random-pick-with-weight/
- https://leetcode.com/problems/insert-delete-getrandom-o1/
- https://leetcode.com/problems/valid-sudoku/
Other resources
Blind 75 ultimate quick question solving:https://leetcode.com/discuss/general-discussion/460599/blind-75-leetcode-questions
This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)". Please keep the following tags for sharing and interpretation:
Original author:Jake Tao,source:"Leetcode question writing method and question type arrangement"
Comment list (4 items)
I found your blog by searching on Google, and found that your career path has many decisions to change tracks, which is very interesting! From cloud to Internet, finance to e-commerce. My peers around me chose Dabao and continued to make progress, but they failed to overcome their poor performance when they were applying for jobs last time. Thanks for your output, which allows me to find real value outside of trolling and bickering in certain forums.
Please look at your information. You are now a senior manager. Do you still need to take these tests during the interview?
@QW :The current trend is for everyone to be able to write code. Although it is not required for daily work, it is basic. I have seen directors take the algorithm test before. In fact, I had a complete preparation and then reviewed it quickly.
good! Like.