Reproduced from:
Mp.weixin.qq.com/s/WhNogMfwR…
zhuanlan.zhihu.com/p/50247385
This evening “high performance server development” QQ group (group number: 49114021, interested readers can add) inside a named “Chengdu-go-quit fried chicken” group friends put forward some of his recent interview questions, interview questions content personally feel very typical, also very representative and targeted, so take it out to share with you, but also thank him for sharing. Chengdu -go- quit fried chicken said:
“What I didn’t answer in the interview today are redis persistence mechanism, redis destruction mechanism, mq implementation principle, c++ virtual function, hash conflict resolution, memcached consistent hash, socket select defect, epoll model, synchronous mutual exclusion, asynchronous non-blocking, callback concept, Innodb indexing principle, one-way graph shortest path, dynamic programming algorithm.”
The interview questions have been slightly modified to avoid ambiguity.
Thought analysis
From the content of the interview questions, it can be seen that this is a backstage development position.
With the exception of the c++ virtual function, most of the other questions are not related to which programming language, most of them are fundamental and basic, and a few are work experience issues, which I try to analyze for you.
Language foundation
C++ virtual function This is an interview question with a 95% probability for entry-level and intermediate C++ positions. There are generally the following kinds of questions:
- In an inherited parent class, when building and destructing a subclass object, what is the order in which the parent constructor and destructor are executed?
- In an inherited class system, must the constructor and destructor of the parent class be declared virtual? What happens if you don’t declare virtual?
- What is C++ polymorphism? What is the implementation principle of C++ polymorphism?
- What is a virtual function? What is the implementation principle of virtual functions?
- What is a virtual table? What is the memory structure layout of the virtual table? What is the first (or second) entry in the virtual table?
- What is the layout of virtual tables in each class under diamond inheritance (class D inherits both B and C, and B and C inherit from A)? If a member of class B and C changes m at the same time, how is M distributed over the memory address of object D? Do they cover each other?
Algorithms and data structure fundamentals
When it comes to algorithms and data structures, they are not the same for social recruiters and fresh graduates, and they are not the same for large Internet companies and small enterprises. The following is based on my experience as an interviewer interviewing others and being interviewed for a job.
First of all, in addition to some special positions, common algorithms and data structures interview questions are as follows:
- Sort by quicksort > bubble sort > Merge sort > bucket sort
Generally for the company with requirements on the basis of the algorithm, if you are a fresh graduate or work experience in one to three years, if the above algorithm can not be written, the impact on the interviewer will be very bad, or even directly passed off. For more than three years of work in society, if you can not write, but can analyze the complexity of its algorithm, the best and worst case complexity, tell the algorithm of the general principle, in front of most interviewers can also pass. Notice, if you’re a student and you can’t write it or write it wrong, you’re not going to pass the interview.
-
Binary search
Binary search algorithms should be written as much as possible. Of course, most interviewers won’t ask you about binary search directly. Instead, you’ll want to think about binary search in context, such as how to find the square root of a number. When I interviewed with Agora at the end of 2017, the interviewer asked me how to quickly find an IP address out of all the IP addresses out there.
-
The list
Whether fresh graduates are not long working years of social people, liantable common operations must be skilled to write out, such as linked list search, positioning, inversion, connection and so on. There are also some classic questions that are often asked, such as how two linked lists can be judged to have rings (I was asked in the second interview of the Shanghai Gold Exchange in 2017). Linked lists are generally not difficult, but there are many “holes” in linked lists, such as many people do not pay attention to boundary checking, empty linked lists, functions that return a linked list should return the head pointer to the list, and so on.
-
Queue and stack
For fresh graduates generally this kind of q is less, but for people in the society, especially senior post development, combined with related question for more, let the interviewer for producers and consumers under the queue to write a multithreaded program, comprehensive resources of the multithreaded synchronization and race problem (detail introduce multithreaded interview questions was below).
The stack generally asks for interviews with high basic requirements in combination with the function call implementation. Calls a function of how to implement, including function of several common call addition ways, order of parameters into the stack, memory, stack in the address from high to low expansion, the position of the stack frame pointer and stack pointer, a local variable in a function in the stack memory distribution, after the function call, the caller and callee who and how to clean up the stack, and so on. One year I was interviewing for a basic department in Jingdong, and the interviewer was asked to write a sum algorithm from 0 to 100, and then write it in assembly code.
-
Hash table
Hash tables are one of the most explored data structures. Common questions include detecting hash conflicts, asking the interviewer to write a hash insertion function, and so on. Basically, an interview without looking at a red-black tree is basically going to ask about hash tables, and the questions can be shallow or deep. What impressed me most was that I asked some questions about hash tables in the second interview of baidu’s advertising recommendation department. When the interviewer ask the linked list, then asked the hash of conflict solution, then let write insert a hash algorithm, it is important to note that your algorithm must be inserted element in the common elements, so the c + + or Java language, be sure to use the template such parameters as the objects of insert hash algorithm. Then, when multiple elements in the hash table conflict, the elements in one position are threaded backwards using a linked list. Finally, the problem of memory fragmentation caused by frequent calls of malloc (ptmalloc below) functions in Linux and the open source solutions TCMALloc and Jemalloc are examined. In general, the interviewer is taking you step by step. (Interested readers can do their own research, there are plenty of relevant materials online)
-
The tree
The trees with high interview frequency are red-black trees, and some are B trees (B+ trees).
Red-black trees generally have a wide range of questions, and most interviewers don’t need candidates to write specific code if they can explain the concept of red-black trees, left-right rotation, average algorithm complexity for lookup and insertion, and best-worst-case algorithm complexity. TreeMap is the equivalent of asking you about red-black trees, so be prepared. I once interviewed iQiyi was asked about red black trees.
B tree is usually not directly asked, the most common form is to ask the MySQL index implementation principle (database knowledge points will be discussed in the following article). The author interviewed Tencent hotspot department two face has been asked.
-
figure
I have never personally encountered the question of figure in an interview, but according to one of my brothers, he had an interview question about depth first and breadth first before he joined Samsung Electronics.
-
Some other algorithms
A* Pathfinding and Huffman Coding are also occasionally asked in interviews at companies in A particular field, such as Baokai (the parent company of Plants vs. Zombies, which has A branch near Shanghai’s People’s Square).
Basic coding skills
There is a bad interview question classification, can be as a encoding the basic skills, this kind of problem can be inspecting algorithm can you write code basic literacy, these qualities not only includes coding style, ability of computer English, debugging, etc, also including you grasp of the details and wrong understanding, such as consciously in inspection of boundary conditions and filtration of illegal value. What is the result of the following code execution? (Questions from my 2011 interview with Dingpu in Zhongguancun, Beijing)
for(char i = 0; i < 256; ++i)
{
printf("%d\n", i);
}
Copy the code
Here are a few more common coding questions:
-
Implement a memmov function
This topic examines the difference between memmov function and memcpy function, the two for the source address and target address memory overlap this situation is not the same.
-
Implement strcpy or strcpy functions
This function is easy to write, but in addition to checking the boundary conditions, it is also easy to overlook that the return value must be the target memory address in order to support what is called chained copy. That is:
strcpy(dest3, strcpy(dest2, strcpy(dest1, src1))); Copy the code
-
Implement the AToi function
This function has the following signature:
int atoi(const char* p); Copy the code
Easy to neglect the following points:
-
Decimal problems, such as the numbers 0.123 and.123, are legal;
-
Sign problems such as +123 and -123;
-
Consider how to identify the first illegal character problem, such as 123Z89, and convert to should 123.
I had this problem when I was interviewing for Master Tech.
Multithreaded Development Basics
Multicore cpus have long been commonplace, and multithreaded programming has “flown into the home”. For most desktop applications (as opposed to Web development), especially for positions like backend development where the candidate is a social person (with some work experience), if the candidate is not familiar with multithreaded programming, he or she will be passed over.
How familiar is “familiar with multithreaded programming”? Generally includes: the need to create new threads, thread, know what kind of situation how to create and wait for, the relationship between threads and processes, thread local storage (TLS or thread local), multi-threaded access resources causes of race and solution, and so on, familiar with the operating system platform to provide various thread synchronization primitives.
For C++ developers, you need to:
- For Windows developers, You need to be familiar with the Interlock series of functions, CriticalSection, Event, Mutex, Semphore API functions and two important functions WaitForSingleObject, WaitForMultipleObjects.
- For Linux developers, you’ll need to be familiar with operating system apis such as Mutex, Semphore, condition_variable, and read-write-lock.
With Java, you need to be familiar with most thread synchronization objects in packages such as the synchronized keyword, CountDownLatch, CyclicBarrier, Semaphore, and java.util.concurrent.
The database
Database knowledge is generally in the big Internet enterprises do not make rigid requirements for fresh graduates, for small Internet enterprises or social people generally have certain requirements. The requirements generally include:
-
Familiar with basic SQL operation
These include insert, DELETE, UPDATE, SELECT statements, sort order, conditional query (WHERE substatement), LIMIT the number of query results (LIMIT statement), etc
-
Slightly more advanced SQL operations (Group by, IN, JOIN, left Join, multi-table union query, use of aliases, SELECT substatements, etc.)
-
Index concept, index principle, index creation skills
-
The operation of the database itself, build the database to build tables, data import and export
-
Database user permission Control (Permission mechanism)
-
The difference between the two MySQL database engines
-
SQL Optimization Tips
Network programming
Network programming, for fresh graduates or entry-level positions generally only ask some basic network communication principles (such as three handshakes and four waves) socket basic API use, The process of network communication between client and server (answer “client creates socket -> connects server -> sends and receives data; server creates socket -> binds IP and port number -> starts listening -> accepts client connection -> communicates and receives data with client”), TCP and UDP differences and so on.
For social people with less than three years of work experience or some intermediate interviewers will generally ask some difficult questions, such as the use of select function, non-blocking connect function writing method, Horizontal and edge patterns of epoll, difference between blocking and non-blocking sockets, return case of send/recv, reuse_ADDR option, etc. Windows platforms may also ask about the use of the WSAEventSelect and WSAAsyncSelect functions, completion ports (IOCP model).
For more than three years, especially those who “claim” to have designed servers and seen open source network communication library code, in-depth questions will be asked. These questions may be common problems in real projects or details of network communication. In my experience, these questions usually include:
- Nagle algorithm.
- Keepalive option;
- Linger options;
- How to solve the problem of a large number of CLOSE_WAIT or TIME_WAIT on one end;
- How to design the communication protocol or how to solve the problem of sticky packet and fragment packet;
- How to design the heartbeat mechanism; (May not directly ask the question itself, such as how to check for dead links)
- How to design the disconnection reconnection mechanism;
- The understanding of IO Multiplexing technology;
- The correct way to send and receive packets, how to design the sending and receiving buffer;
- Gracefully closed;
- How to design timer;
- Implementation principle of epoll.
For example, let the reader feel, the author once went to BiliBili and was asked this question: if machine A and machine B have never sent data to each other after the network connection is successful, and one machine suddenly loses power at this moment, what is the state of the network connection between the other machine and the machine without power?
Memory database technology
Nowadays, memory database based on NoSql key-value is very popular and widely used in various background project development. Therefore, it is a basic requirement to be familiar with one or several in-memory database programs. Among them, Redis and memcached are the most typical representatives. Here, Redis is taken as an example.
-
The first level is generally an examination of the basic usage of redis
For example, consider the basic data types supported by Redis, redis data persistence, transactions, etc.
-
The second level not only examines the basic usage of REDis, but also goes deep into redis source code, such as redis network communication model, the realization of various data structures of Redis and so on.
In my opinion, Redis is an open source software worthy of learning, whether from the perspective of job interview or technology improvement. I hope readers can consciously understand and learn it.
Experience in project
In addition to social recruitment and some small enterprises, general large Internet companies do not require too much project experience for fresh graduates, but hope that they have a solid foundation of algorithms and data structures, and strong practical ability. For the general small company, for fresh students will require it at least skilled in the use of a programming language and the corresponding development tools, known as familiar with Linux C++ development interviewees, not familiar with GDB debugging is basically not really familiar with Linux C++ development; Being familiar with assembly or disassembly, not IDA or OllyDbg, is basically a misnomer; Known to be familiar with VC++ development, even F8, F9, F10, F11, F12 and other shortcut keys are not familiar with is difficult to stand the interviewer’s questions; It doesn’t make sense for someone who claims to be familiar with Java development to be unfamiliar with IDEA or Eclipse.
Here to some education is not good, the school is not very famous, especially the following two students want to enter the IT industry a suggestion, in addition to learning the basic knowledge of computer during the university, must be skilled in the use of a programming language and the corresponding development tools.
About project experience, many interviewees think that must be involved in the project, but also can learn from you and read others’ source or open source software source code, if you can understand and grasp the idea of these open source software and technology, to be able to talk with the interviewer during the interview, the interviewer will be very satisfied. Some time ago, one of my junior students told me that he read my public account [easyServerDev] “server development foundation series and advanced” article, successfully got the offer of netease, interested readers can have a good look.
Many students may be torn about whether to work on projects with their tutors in college or graduate school. Of course, if these projects are required, then you must attend them; If these projects can be optional, especially some of the so-called packaging and processing with only a third party library, then it is recommended to participate in less.
Thinking summary
I do not know through the above technical analysis, smart readers have been clear at the beginning of this article “Chengdu-Go-quit fried chicken” students proposed in the interview questions, which are the technical interview difficult points, which is the technical development of the difficult points?
Skill share and salary
Based on my own experience in hiring, I would like to talk about the skill level and salary.
- Level 1: If the interviewer can answer the above interview questions based problem and algorithms and data structures in c + + title (such as c + + function index of the solution of the conflict with the hash, innodb principle, ChanXiangTu shortest path, the dynamic programming algorithm, etc.), can think the interviewer is a qualified initial, intermediate developers, salary range in 6 ~ 12 k (note: This is based on Shanghai, where I live).
- Second level: On top of the first level, if the candidate can also answer the network programming or multithreaded questions mentioned above (defects of socket function SELECT, epoll model, synchronous mutex, asynchronous non-blocking, callback concept, etc.), the candidate is considered to be an intermediate developer with a good foundation. The salary range is generally between 14 and 22K.
- Level 3: Between the first two levels, if the candidate can also answer the above questions about redis, memcached and MQ implementation principles, the candidate has good project experience and understanding of some common open source projects, the salary will be 22K +.
conclusion
Salary income is everyone’s secret, generally not easy to outsiders. I just want to say that the best way to raise your salary for the average developer is to improve your skills. Whether it’s search engine oriented programming or salary oriented programming, you’re smart enough to think ahead.
How to Negotiate salary? What’s the trick? Please refer to:
Mp.weixin.qq.com/s/AITgXpK8y…