The Ant Problem | Microsoft , Adobe Interview

There are 100 ants on a board that is 1 meter long, each facing either left or right and walking at a pace of 1 meter per minute.

The board is so narrow that the ants cannot pass each other; when two ants walk into each other, they each instantly turn around and continue walking in the opposite direction. When an ant reaches the end of the board, it falls off the edge. From the moment the ants start walking, what is the longest amount of time that could pass before all the ants have fallen off the plank? You can assume that each ant has infinitely small length.





Solution :

The longest amount of time that could pass would be 1 minute.

If you were looking at the board from the side and could only see the silhouettes 
of the board and the ants, then when two ants walked into each other and turned 
around, it would look to you as if the ants had walked right by each other.

In fact, the effect of two ants walking into each other and then turning around 
is essentially the same as two ants walking past one another: we just have two 
ants at that point walking in opposite directions.

So we can treat the board as if the ants are walking past each other. In this 
case, the longest any ant can be on the board is 1 minute (since the board is 
1 meter long and the ants walk at 1 meter per minute). Thus, after 1 minute, 
all the ants will be off the board.

Leave a Reply

Your email address will not be published. Required fields are marked *

For Inserting code :
Paste your code in the comment form, select it and then click the language link

C | C++ | Java |