Column | chapter nine algorithm

Url | http://www.jiuzhang.com

In interviews, we often emphasize trying to be bug-free. However, in fact, even the most top software engineers, it is difficult to be bug free in the interview at once.

Therefore, the interviewer will not fail you in the interview because of a bug in your code. They tend to focus more on you:

Are you aware of bugs

Know how to identify and fix bugs.

1. Which interview bugs are fatal and which ones aren’t?

During the interview process, the code of the candidate is actually used as an example to test the candidate’s programming ability. Everyone will inevitably have bugs in the coding process, and the interviewer will judge your shortcomings in programming ability according to your bugs. Some weaknesses, which can be fatal, can cause you to fail the interview directly; And some short board, it is not hurt elegant, irrelevant.

1. A bug that may not matter

For example, this Java code:

There is a “big” bug in this code, and in line 2, you should write Add instead of INSERT. If the interviewer writes code like this, the code won’t run.

But interviewers are not picky, and they don’t reject candidates because of it. They may not even notice the bug. This is just a code example for them to infer that the candidate might not use the built-in linked list class. The interviewer probably doesn’t care.

2. Fatal Bug that can ruin an interview

Example 1:

There are some problems with this code:

1. If the array is empty, the program will crash at line 2.

2. The for loop starts at I =0, but it doesn’t have to. It should start at I =1.

3. The for loop conditions the array length, each time to extract the array length, add steps.

4. Bad logic in line 4

There are four errors in this simple code that should worry the interviewer. He will conclude that although the candidate can code, the candidate does not code often (because of question 3). And failing to write such a basic for loop can make the interviewer worried about the candidate’s abilities.

Example 2: Here is a real code from the interview:

This code is more than just careless. It makes no sense at all, and the interviewer will silently give the candidate a very, very low grade.

However, if the bugs are easily found and fixed, the number of bugs is reduced.

2. How to identify and fix your bugs during the interview?

Almost all candidates will have coding bugs in the interview, but if they can quickly find and fix these bugs, it will not affect the interviewer’s score on them. Therefore, learning how to identify and fix bugs is a very important skill.

Many candidates panic when they spot a mistake. They find a bug in a particular test and quickly fix it in retrospect. The best thing you can do is pass the test, but if you don’t, it’s embarrassing.

Example:

For example, this code looks for string S in string B

Did you notice a bug?

At first glance, the code looks basically correct.

But the interviewer is using a test data s= “xyz” and b #ERROR! Bug, the interviewer will notice that the for loop is never executed. It would be unreasonable for an interviewer to assume that this bug only occurs when two strings are equal in length, and then try to determine whether they are equal. The for loop deals with enumerating possible starting positions, so the possible starting positions are 0 ~ b.length() -s.length (), The boundary condition of the enumeration should be either I <= B.length () -s.length () or I < B.length () -s.length () + 1, which is the key to this bug. When finding bugs, we should find out the essence of the cause, rather than through if patching, which may add more bugs.

Interviewers generally don’t care that a bug exists, and it’s better if you make a bad fix. Bad fixes don’t fix the problem, they add unnecessary code and, at worst, they introduce new bugs instead of fixing them.

So, when you find a bug, think carefully before you fix it!

3. Failed the interview even though you’ve worked out all the questions?

Some candidates feel good about themselves during the interview process, but then receive rejection letters. They might be surprised to learn that their code is “completely correct” and rejected. But they don’t realize that accuracy alone is often not enough.

In fact, correctness is only part of what the interviewer is evaluating your code for. In the interview process, ** interviewers are looking for a variety of skills, ** may be looking at your technical knowledge, code style, modular ability, rigorous ability, etc. You may be bug-free in one topic, but if you accidentally reveal your weak analytical and coding skills in the process, you will definitely get the attention of the interviewer.

4. Don’t panic if there are bugs in your interview

In summary, there is no need to focus too much on the bugs in coding interview. Thinking logic is the key to coding interview. Be confident when interviewing for coding. Do not rush to modify a coding bug, but think about the cause before fixing it. Calmness shows the true competence of an interviewer.

Dynamic needle parting

Welcome to follow my wechat official account: Ninechapter.



Elite programmer exchange community, regular release of interview questions, interview skills, job information, etc