# What do candidates want for a coding interview?

*Hi, Habrovsk. On the eve of the start of the Java QA Engineer course, we are sharing with you the continuation of this material*

.

At my first interviews, I did not know this. But the developers did not just watch me – they expected. They expected me to act according to the following algorithm:

**Refine the task**

- Ask: “What do you mean by the word palindrome?”
*This answers the question: will the candidate begin to solve the problem immediately – without even realizing that its technical conditions are not completely clear? Or think a little and clarify the requirements? ”*

“We mean a sequence that reads the same from left to right and from right to left. Your decision must be case sensitive: small r is not identical to large r. "

**Start with examples**

- Ask: “The words“ income ”and“ hut ”are given as examples. What about phrases like "Did the rose fall on Azora's paw?" What about an empty string or single character string?
*This answers the question: will the candidate take into account a sufficient number of borderline cases? How accurate and attentive will it be?*

### Before starting the code description, briefly familiarize the interviewer with the algorithm

*How does the candidate approach the solution of the problem? Does he speak his thoughts out loud so that the interviewer hears them?*

For instance, `string s = "alla"`

.

We can use the helper method for the Java String, charAt (int i). Enter the index of the string into the method and it will output the character at the following index:

```
s.charAt (0) == 'a'
s.charAt (1) == 'l'
s.charAt (2) == 'l'
s.charAt (3) == 'a'
```

To find out the length of a string, you can use the method `length ()`

:

`s.length == 4`

To find out the last character, you can use:

```
int len = s.length
s.charAt (len - 1)
```

We started the count from 0, so the last character will be “length minus 1”.

Let's call the first character “first” and the last “last”.

- If the first character s.charAt (first) does not match s.charAt (last), then this is not a palindrome. Output false.
- If the first character of s.charAt (first) matches s.charAt (last), we proceed to evaluate the next set of characters, shifting one character from “first” and from “last”. If everything matches, print true.
- After checking the algorithm with the interviewer, you can start writing code:

```
public boolean isPalindrome (String s) {
int first = 0;
int last = s.length () - 1;
while (first <last) {
if (s.charAt (first)! = s.charAt (last)) {
return false;
}
first ++;
last--;
}
return true;
}
```

### Debugging and testing

- Take the initial test cases and try to imagine: what happens if you insert them into the code.
- Interviewers check your attentiveness when debugging. (
*Do you notice errors in your own code without hints from the outside?*) - Interviewers will give hints if you manage to make a good impression on them. (
*If we give the candidate tips, will he use them? Is he ready to listen to someone else's opinion? Does he know how to work with people in higher positions?*)

### Show your code to other people and collect their feedback

I showed my solution to the palindrome problem to my friend-developer. He grimaced: “Why did you use the variables“ first ”and“ last ”? And why did you use the “loop” cycle if you can get by with the “for”? Everything could be made shorter, more elegant and faster:

```
public boolean isPalindrome (String s) {
int len = s.length;
for (int i = 0; i <len / 2; i ++) {
if (s.charAt (i)! = s.charAt (len - 1 - i)) {
return false;
}
}
return true;
}
```

### What's next

Mastering the programming language overnight does not work. Therefore, it is better to follow this algorithm:

- Find online programming tasks at a basic level.
- Try to solve them with paper and pen.
- If you cannot solve them, check out the official documentation of the programming language and see which built-in methods can help you.
- Formulate your own decision before looking for someone else's. If you yourself will collect information and study it, there will be a chance that this information will permanently settle in your head.
- Do not arrange cramming sessions. So you just save the information in short-term memory.
- Practice short runs, 15 minutes a day. So the information will move into a long-term memory, and you can remember it even with extreme stress during the interview.
- Do not expose yourself to all this torment just to pass the test on the board. Aim higher! Set yourself the task of becoming a more professional programmer!