Solid basic knowledge, high-quality code

Source: Internet
Author: User
Tags abstract arithmetic data structures hash require sort

Solid basic knowledge, high-quality code, clear thinking, the ability to optimize code, and excellent comprehensive ability are the five main points of programming technology interview.

Finding a job has always been a hot topic. To find the right job, you will inevitably have to go through multiple rounds of interviews. Programming interviews are the most important part of a programmer's interview process. If you can fully demonstrate your ability in the programming interview, then get the preferred offer is the thing.

I have been a software engineer at Autodesk, Microsoft and Cisco, and have been interviewed by others for many times and interviewed a lot of people. Summing up the interview and interview experience, I found that although the interviewer's background and personality are different, but are concerned about the five qualities of the candidate: a solid basic knowledge, the ability to write high-quality code, analysis of the problem with clear thinking, to optimize time efficiency and space efficiency, with learning ability, communication skills, The ability of divergent thinking and so on.

1. Solid Basic Knowledge

Solid basic skills is to become a prerequisite for good programmers, so the interviewer's first concern about the quality of candidates is a solid foundation. Usually the basic skills in the programming interview is embodied in two aspects: one is programming language, the other is data structure and algorithm.

Each programmer must be proficient at least one-to-one programming language. The interviewer can see the proficiency of his programming language mastery from the code written by the candidate during the interview and follow-up questions. In C + + as an example of most company interview requirements, if a function needs to pass in a pointer, the interviewer may ask if you need to add a const to the pointer, what is the difference between a const and a pointer in a different position; if the function you write needs to pass in a parameter that is an instance of a complex type, The interviewer may ask what the difference is between an incoming value parameter or a reference parameter, and when you need to add a const to the incoming reference parameter.

Data structures are often the focus of the programming interview process. Before interviewing, candidates need to be proficient in data structures such as lists, trees, stacks, queues, and hash tables, as well as their operations. If we pay attention to the questions of the major companies, we will find that the linked list and the two-tree related questions are the questions that many interviewers like to ask. The problem seems simple, but the real mastery is not easy, especially for a few 10 minutes of interview time to test the basic skills of candidates. If the candidate in advance to the list of insertion and deletion of the node is well-versed in the two-fork tree of various traversal methods of the loop and recursive method of writing are familiar to the chest, then really to the interview is also easy.

Most companies ' requirements for algorithms are simply to look up and sort. Candidates can learn a variety of search and sorting algorithms based on the focus on the binary search, merge sorting and quick sorting, because many of the interview questions are just variants of these algorithms. For example, move the number of numbers in front of a sorted array to the back of the array and ask how to find the smallest number in the array. The essence of this problem is to examine the binary search. A handful of companies that value algorithms, such as Google or Baidu, also require candidates to master dynamic programming and greedy algorithms. If you are interested in this type of company, then the candidate should strengthen the practice of the relevant algorithm topics before attending the interview.

2. High-quality Code

Only quality-oriented programmers can write robust and stable large-scale software. In the interview process, the interviewer will be particularly concerned about the boundary conditions, special input and other seemingly trivial but essential places, in order to analyze whether the candidates pay attention to code quality. Most of the time, the interviewer finds that the code written by the candidate can only perform the most basic functions, and once a special boundary condition parameter is entered, it will be riddled with errors or even a program crash.

A question that many candidates have been asked: Write a function that converts a string into an integer. This problem seems very simple, most of the computer professional graduates can use 10 lines of code to achieve the most basic functions. However, in the actual interview process, only one of the 10 candidates can pass the interview, because most candidates can not fully consider all kinds of special input, such as the input string contains a non-numeric symbol, at the beginning of the string is signed, the string has a sign but its position is not at the beginning of the string.

In addition, the interviewer wants the candidate to consider boundary conditions including 2147483647 (the largest positive integer 0x7fffffff,int can represent) and -2147483648 (the smallest negative integer that 0x80000000,int can represent).

In addition to the lack of boundary conditions and special input considerations, the interviewer has an intolerable error that the program crashes. Many candidates in the interview forget to do special handling of the null pointer and cause the program to crash. If the interview encountered linked lists, binary tree related topics, candidates must be particularly careful. Because there are usually a lot of pointers in the code for both of these topics, it is possible to operate on a null pointer and crash the program if it is poorly thought out.

For example: Enter a list of the head pointer and an unsigned integer k, output the list of the penultimate node K. Many people can think of this problem with two pointers: the first pointer moves k-1 on the list, while the first pointer and the second pointer move on the list. When the first pointer moves to the tail pointer, the second pointer points to the reciprocal K-node. However, not every candidate can write the complete code according to the correct idea. Many candidates will overlook two possibilities: first, the input of the linked list head pointer may be a null pointer, and the second is that the number of nodes on the list may be less than K. Ignoring the two-point code has the potential to crash, making it difficult to get the interviewer's favor.

To write robust, high-quality code, you need to think about test cases before you write your code. Before writing the code, consider the various boundary conditions and special inputs as test cases. When the code is written, use the test cases that you have thought of before to test the code you write, so that you can find and solve the problem before the interviewer. To the list of the last K-node, for example, if you think of the input head pointer to null pointer and the total number of nodes on the linked list is less than the two test cases, and after writing the code in mind to simulate the operation of the Code, to ensure that the two test cases can pass the test, then this interview must be able to pass.

3. Clear Ideas

Only when the idea is clear, can candidates solve complex problems during the interview process. Sometimes the interviewer will deliberately come up with some more complex questions to examine whether a clear idea can be formed and the problem solved in a short time. For a really complex problem, the interviewer doesn't even expect the candidate to give a complete answer in less than one hours of the interview, and he's more likely to focus on whether the candidate has a clear idea. Interviewers often don't like candidates to start writing code hastily before they have a clear idea, and the resulting code is easy to write and confusing.

Candidates can help themselves to form clear ideas in a few simple ways.

The first is to give some simple concrete examples to understand the problem. When you see no problem in the hidden laws, you can try to use one or two specific examples to simulate the process of operation, it may be possible to find concrete examples of abstract laws.

Second, you can try to represent the abstract data structure graphically. When analyzing topics related to linked lists and binary trees, you can draw their structure diagrams to simplify the problem.

Finally, we can try to decompose complex problems into several simple sub-problems, and then one by one solve them. Many of the ideas based on recursion, including the division and dynamic programming methods, are the decomposition of complex problems into one or more simple sub-problems.

For example, the problem of converting a two-fork search tree to a sorted two-way list is complicated. If you encounter this problem, you may want to draw one or two specific two-fork search tree and its corresponding sort of two-way linked list, intuitively feel the binary search tree and the sort of two-way linked list of what links. If you can't find the law of conversion, you can see the whole binary tree three parts: root node, Saozi right sub-tree. When the transformation of the left and right sub-tree of the two sub-problem, then the transformation of the left and right sub-tree to get the linked list and root node link up, the whole problem is solved.

4. Ability to optimize code

Good programmers spend pinching irritate D on time and space, and they are passionate about constantly optimizing their code. When the interviewer has a variety of solutions to the problem, he usually expects the candidate to eventually find the best solution. This requires the interviewer to suggest that there is a better solution, not to give up thinking, but should try to find in time consumption or space consumption can be optimized place.

To optimize time or space efficiency, you first need to know how to analyze efficiency. Even the same algorithm, the efficiency of the implementation of different methods may also be large, to be able to analyze the algorithm and its code implementation efficiency. For example, for the Fibonacci sequence, many people prefer to use the recursive formula F (n) =f (n-1) +f (n-2) solution. If the recursive call tree is analyzed, a large number of computations are repeated, and the time efficiency is increased by the exponent of N. But if you first ask F (1), F (2), according to F (1) and F (2) to find F (3), Next according to F (2), F (3) to find F (4), and so on with a loop to find F (n), the time efficiency of the calculation method is only O (n), much better than the previous recursive method.

To optimize the efficiency of the Code, but also to understand the advantages and disadvantages of various data structures, and to choose the appropriate data structure to solve the problem. We can use O (1) to complete the search in the array according to the subscript. This feature of the array can be used to implement a simple hash table that solves many interview questions, such as finding the first occurrence of a character in a string. For example, to find the smallest number of k in n numbers, a data container is needed to store the K numbers. In this data container, we want to be able to quickly find the maximum value and quickly replace the number in it. By trade-offs, we have found that two-fork trees, such as the largest heap or red-black tree, are ideal for this data container.

To optimize the efficiency of the code, you also have to master the commonly used algorithms. The most common algorithms for interviewing are finding and sorting. If you scan an array from beginning to end, an O (n) time is required to complete the lookup operation. However, if the array is sorted, the time complexity can be reduced to O (Logn) by applying the binary lookup algorithm. Sorting algorithms can be used to solve other problems in addition to sorting the array. For example, the partition function in the fast sort algorithm can be used to find the number k in the n number, so that the number of occurrences more than half the length of the array can be found in the array using O (n) time. If the interview question is a problem that asks for the maximum or minimum value, you can try the dynamic programming method or greedy algorithm, for example, using dynamic programming method to find the maximal and the continuous subarray in the array.

5. Excellent comprehensive ability

In the interview process, in addition to demonstrating their programming skills and skills, but also need to demonstrate their soft skills, such as communication skills and learning ability. With the scale of software systems growing, software development has been farewell to the era of single-fight, programmers and other people's communication becomes more and more important. In the interview process, the interviewer will observe the candidate in the introduction of project experience or algorithmic thinking is clear, logical clear, and to judge his ability to communicate. In addition, the interviewer will look at the attitude and tone of the applicant's speech to determine whether he has a sense of teamwork. Usually the interviewer doesn't like people who are arrogant or despise collaborators.

It industry knowledge is very fast, so programmers only have a good learning ability to keep abreast of the pace of change. Usually the interviewer has two ways of examining the candidate's ability to learn. The first approach is to ask the candidate what books they are reading recently and what new technologies they have learned. The interviewer can use this question to understand the candidate's learning aspirations and learning ability. The second approach is to throw a new concept, and then he will see if the candidate can understand the new concept and solve the problem in a short time. For example, the interviewer asks the candidate to calculate the 1500th number of ugly. Many people have not heard of the concept of ugliness. At this point the interviewer will observe the new concept of the number of ugly candidates, can ask questions, think, and then ask the process, finally find out the law of the ugly number to find a solution.

The ability of knowledge transfer is a special learning ability. Learning new technologies or solving new problems can be easier if we can move what we already know into other areas. Interviewers often ask a simple question and then ask a very complicated question that is related to the simple question ahead. At this point the interviewer expects the candidate to get a hint from the simple question and find a knack for solving the complex problem. For example, the interviewer asked the candidate to write a function for the Fibonacci sequence, and then asked a frog to jump the steps of the problem: a frog can jump on the level of 1 steps, can also jump on the 2 steps, ask this frog jumped on the N-level total number of steps to jump. If the candidate has a strong knowledge transfer ability, it can be analyzed that the frog jumping step problem is essentially an application of the Fibonacci sequence.

There are many interviewers who like to examine the candidate's abstract modeling and divergent thinking abilities. The interviewer extracts questions from daily life, such as how to determine whether 5 cards are straight, and to examine if the candidate can abstract the problem out with a reasonable data structure and find the rules to solve the problem. Interviewers can also restrict candidates from using conventional methods, which require the candidate to be innovative and open up ideas to analyze and solve problems from multiple angles. For example, the interviewer asks the candidate not to subtraction arithmetic to achieve the addition of two integers. At this point the interviewer expects the candidate to open up ideas and use bitwise arithmetic to achieve the addition of integers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.