# Top 25 questions for a phone interview you should know – Part 2

In the previous part of this article, we have already considered 25 questions that you can ask in a telephone interview for the post of programmer. In this part, we will consider another 17. The range of complexity of the questions is wide enough, so we recommend that you familiarize yourself with all of them.

#### 26. What is test-driven development?

This is one of the popular approaches to development, in which tests are written before any code begins to be written. In fact, in this case, your code is adjusted to the written tests. Purists generally will never write a line of code without a test for it. This approach greatly improves the quality of your program and is often considered a sign of professionalism.

#### 27. What is the difference between a binary tree and a binary search tree?

A binary search tree is an ordered search tree in which all values to the left of its ancestor are less than it, and to the right of it are greater or equal to it. This is an important data structure that can be used to represent ordered data.

#### 28. List the ways to resolve collisions in the hash table.

Linear sampling, double hashing and clutching. In the case of linear probing, if the basket with the desired hash is already occupied, another free basket will be searched, while several elements may be stored in the same basket when linked.

#### 29. What is the principle of openness / closure? (answer)

The principle of openness / closure implies that any system should be open for expansion, but closed for modification. That is, if you have a well-functioning tested system, and you need to add new functionality to it, you should do this by adding new classes, and not changing the old ones (as is known, if something works, then do not touch it) .

#### 30. How do I get the last digit of a number? (answer)

If you divide the number by 10 with the remainder, the resulting remainder will be the last digit of the number. So, for example, it `2345 % 10`

will be 5, and `567 % 10`

– 7. This works the other way too: integer division can be used to get rid of the last digit of the number: it `2345 / 10`

is 234, and a `567 / 10`

is 56.

#### 31. Can you give a practical example of a recursive algorithm? (answer)

There are many examples of using recursive algorithms in practice – for example, in binary search trees and linked lists. Recursion can be used when calculating Fibonacci numbers, flipping a string or a linked list, traversing the graph and quickly sorting.

By the way, recursion is important to be able to optimize .

#### 32. What is the time complexity of the algorithm?

The temporal complexity of the algorithm shows the relationship between the amount of input data and the program time. The temporary complexity gives you an approximate idea of the speed of the program and how much its time will increase with increasing the number of input data from ten to ten million.

#### 33. What is the difference between a linked list and an array? (detailed answer)

A coherent list and an array are one of the main data structures in programming. The memory for the array is allocated with one continuous piece, and the elements of the linked list can be scattered across the entire memory, which gives it the ability to expand itself almost infinitely as long as there is free memory. A situation may arise that you can not store one million integers in an array, but you can do this using a linked list. All other differences between the connected list and the array follow from this basic difference. For example, you can find an element in the array after O (1), if you have an index of this element, but in a linked list it will take O (n).

#### 34. What is the “replacement principle of Barbara Liskov”? (answer)

The principle of substitution of Barbara Liskov implies that each type should be completely replaced by its subtypes, if any. For example, if a method takes an object of a class as an argument `Parent`

, then it must accept the object of the class `Child`

inherited from `Parent`

. Each class that can not replace its parent violates the principle of Barbara Liskov. This is a difficult question, and if you can answer it, you will surely make a good impression on the interviewer.

#### 35. What is a “regular expression”? (answer)

A regular expression is a way to map large text data to a sample. For example, using regulars, you can check whether there is a certain character in a very long string, or whether the book contains the word you are looking for. Almost all programming languages support regular expressions, but Perl stands out among them. Java supports Perl regular expressions when used `java.util.regex`

. You can use regular expressions to check the email address, zip code or even SSN number for validity. One of the simplest examples of usage is checking whether the string is numeric (that is, it contains only digits).

We recommend reading the material about the use of regular expressions in Python (for beginners)

#### 36. What is a “no-state” system?

Such a system does not have any internal state, and therefore, with the same input data, the same output will be obtained. A system without a state is always easier to program and optimize, which means it is worthwhile to develop the software in such a way that the state in it is present minimally.

#### 37. Write a SQL query to get the second largest salary from the employee database (solution)

Classic, but from this no less interesting question, with the help of which you can check the degree of knowledge of the candidate in SQL. This task can be solved using a correlated and uncorrelated subquery. Also you can use keywords `TOP`

or `LIMIT`

, if you use SQL-server or MySQL, depending on what the interviewer asks. The simplest way to solve the problem:

```
SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee)
```

This request will find the highest salary, exclude it from the list and find the next maximum, that is, the second largest.

#### 38. Can you describe the difference between a correlated and uncorrelated subquery? (answer)

In a correlated subquery, the internal query depends on the external query, which means that both requests are executed sequentially, while in uncorrelated subqueries they do not depend on each other and can be executed independently of each other. In this regard, the correlated query is slower than the uncorrelated query, but the correlated one has several remarkable applications – for example, getting the second highest salary from the database (see the previous question).

#### 39. How to check whether a number is a power of two without using arithmetic operators? (decision)

Once you hear that the question is not about arithmetic operators, feel free to think that it’s about bit operators. If there are no restrictions on the operators used, then you can solve this problem by obtaining the integer part of the division and the remainder of the division. Otherwise, use this trick with the AND operator:

```
public static boolean powerOfTwo(int x) {
return (x & (x - 1)) == 0;
}
```

And in the context of such a question they may ask: what is 2 ^{64} ?

#### 40. How to find the running process on UNIX? (command)

You can use a combination of commands `ps`

and `grep`

to find any running process on UNIX. Suppose that the process you need has a name or some text with which you can find it:

`ps -ef | grep "myProcess"`

PS `-e`

will look for all processes, not just running under the current user, but `-f`

will give out full information about the process, including the PID, which you can use to kill the process with `kill`

.

In general, there are a lot of useful Linux commands that save you time – and you probably did not even know about them.

#### 41. How to find large files on UNIX (for example, more than 1 GB)? (command)

You can easily do this with a command `find`

, because it gives you the ability to search for files by their size. The following command allows you to find all files larger than 1 GB, but it is obvious that the size of the files you search for is easy to change. For example, in order for a team to search for files less than 100 MB, it’s enough to replace it `+1G`

with `+100M`

.

`find . - type f -size +1G -print`

#### 42. What is a shell script?

Shell-script is a set of commands with some features from programming – for example, constructions `if`

and `for`

. Thus, using shell scripts, you can automate routine work such as daily cleaning logs, creating backups, etc.

The list of questions came to an end. We have not reached very much to 50.