Skip to content

тест на вакансию Junior Java Developer

Notifications You must be signed in to change notification settings

4kin/test-HR-Link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

тест на вакансию Junior Java Developer

We have a wooden plank of the length n units. Two ants are walking on the plank, each ant moves with a speed of 1 unit per round. One ant moves to the left, the other moves to the right. At one round, each ant makes a move. Ant walking to the left moves first.

If an ant is going to move to a point that is already occupied by another ant, then each of the ants change direction and only after that the current ant moves. Assume changing directions does not take any additional round. Also, ants cannot take the same position on the plank.

When an ant reaches one end of the plank and moves towards the end of the plank, it does not fall out of the plank immediately, it happens in the next round.

Given an integer n — plank length and two integers: left — the position of the ant which moves to the left and right — the position of the ant which moves to the right. Return number of rounds needed to get the first ant falls out of the plank.

Constraints:

1 <= n <= 10^4

0 <= left <= n

0 <= right <= n

left != right 1-2.png 3-4.png

Код программы на Java, в котором есть метод, принимающий значения n, left, right, и возвращающий по заданным данным правильный ответ по условию задачи.

About

тест на вакансию Junior Java Developer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages