# IT training - relevant brain teasers from leading companies

Many have heard about tricky questions and tasks that they give at interviews in Google, Microsoft, Apple, Intel, IBM, Amazon, SpaceX, Yahoo, Facebook, etc., as well as Russian Yandex and Mail.ru. They are aimed at assessing technical skills or testing university knowledge, logic, and thinking.

Before submitting a resume, it is better to thoroughly prepare, having solved at least several of these problems. Real tasks can be found on the net. They are laid out by both developers and the companies themselves.

With this article, we open a section in which we will publish several fresh tasks or questions. Answers and decisions will appear within a week after publication. You can also suggest your solution in the comments.

This week we publish**Google**developers .

1. Create a random 4-digit even number. Two adjacent digits must be different.

2. For the entered word, find the following in lexicographic order from those presented in the array.

Example:

Can you use a tree to solve it?

3. Given an array of integers, print all the numbers that satisfy the following requirement:

when the number is greater than each number on the left and less than each number on the right.

4. For a string chemical formula like “C6H2 (NO2) 3CH3”, output a card with a key as an element and a value as its number. An element can have two characters, for example Fe2 (SO4) 3

5. At school, the student receives a reward if he has no more than 1 pass and 3 delays. Considering the student attendance record, represented by a line with three possible characters “L” (“Late”), “A” (Absent), “O” (“Arrived on time”).

Check if the student is eligible for rewards. Example:

A student cannot claim a reward because LLA means that he is late 3 times in a row.

If it is known that the length of the attendance line is n, how many ways are there to visit with a fee.

Translating technical texts was not easy, even with the help of experienced developers. Judging by your comments, we could not cope, so we give the source in English below. Some tasks, possibly in the original, were also given incorrectly.

1. Generate a random 4-digit even number: the adjacent 2 digits must be different.

2. Find the Lexicographic next word of the input word from a list of words

Example

3. Given an array of integers, print all the numbers that meet the following requirement - when the number is greater than every number on its left and smaller than every number on the right.

4. For a string chemical formula like “C6H2 (NO2) 3CH3”, and output a map with key as element and value as its count.

element can have two chars, for example Fe2 (SO4) 3

5. In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.

Given a student's attendance record represented by a string with 3 possible characters 'L' (Late), 'A' (Absent), 'O' (On time),

check whether the student qualifies for the reward.

eg

The student does not qualify for reward because “LLA” means he was late for 3 times in a row.

Follow-up:

If known the length of the attendance string is n, how many possible ways there is to attend school and make sure you get the reward.

Before submitting a resume, it is better to thoroughly prepare, having solved at least several of these problems. Real tasks can be found on the net. They are laid out by both developers and the companies themselves.

With this article, we open a section in which we will publish several fresh tasks or questions. Answers and decisions will appear within a week after publication. You can also suggest your solution in the comments.

This week we publish

**5 interesting tasks.**recently proposed to solve by1. Create a random 4-digit even number. Two adjacent digits must be different.

```
public int getNumber(){
}
```

2. For the entered word, find the following in lexicographic order from those presented in the array.

Example:

List of words:

[Cat, dog, cow, donkey, zebra, monkey],

input

duck

output

monkey

Input

dog

output

donkey

Can you use a tree to solve it?

`public String findNextWord(List` words, String input){
}

3. Given an array of integers, print all the numbers that satisfy the following requirement:

when the number is greater than each number on the left and less than each number on the right.

4. For a string chemical formula like “C6H2 (NO2) 3CH3”, output a card with a key as an element and a value as its number. An element can have two characters, for example Fe2 (SO4) 3

`public HashMap` getCount(String chemicals){
}

5. At school, the student receives a reward if he has no more than 1 pass and 3 delays. Considering the student attendance record, represented by a line with three possible characters “L” (“Late”), “A” (Absent), “O” (“Arrived on time”).

Check if the student is eligible for rewards. Example:

```
@INPUT (String) "OLLAOOOLLO"
@RETURN (Boolean) False
```

A student cannot claim a reward because LLA means that he is late 3 times in a row.

```
@INPUT (String) "OLLOAOLLO"
@RETURN (Boolean) True
```

*Additionally*:If it is known that the length of the attendance line is n, how many ways are there to visit with a fee.

**NB**Translating technical texts was not easy, even with the help of experienced developers. Judging by your comments, we could not cope, so we give the source in English below. Some tasks, possibly in the original, were also given incorrectly.

1. Generate a random 4-digit even number: the adjacent 2 digits must be different.

```
public int getNumber(){
}
```

2. Find the Lexicographic next word of the input word from a list of words

Example

Words list

[Cat, dog, cow, donkey, zebra, monkey],

input

duck

output

monkey

Input

dog

output

donkey

Can you use trie to solve it?

`public String findNextWord(List` words, String input){
}

3. Given an array of integers, print all the numbers that meet the following requirement - when the number is greater than every number on its left and smaller than every number on the right.

4. For a string chemical formula like “C6H2 (NO2) 3CH3”, and output a map with key as element and value as its count.

element can have two chars, for example Fe2 (SO4) 3

`public HashMap` getCount(String chemicals){
}

5. In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.

Given a student's attendance record represented by a string with 3 possible characters 'L' (Late), 'A' (Absent), 'O' (On time),

check whether the student qualifies for the reward.

eg

```
@INPUT (String) "OLLAOOOLLO"
@RETURN (Boolean) False
```

The student does not qualify for reward because “LLA” means he was late for 3 times in a row.

```
@INPUT (String) "OLLOAOLLO"
@RETURN (Boolean) True
```

Follow-up:

If known the length of the attendance string is n, how many possible ways there is to attend school and make sure you get the reward.