Apple Interview Question: Ants are at the corners of an... | Glassdoor

Apple

## Interview Question

Software Engineer Interview

# Ants are at the corners of an equilateral triangle labelled

1, 2, and 3, each ant starts moving towards the next one (1 towards 2, 2 towards 3, 3 towards 1) at the same constant speed. How long until they meet ?

0

I couldn't come up with a good answer, don't know if I am weak in geometry, calculus, logic, or just not smart enough.

Interview Candidate on Jan 25, 2014
8

Ants are never going to meet. because by the time 1 reaches 2 , 2 will reach 3 and 3 will reach 1. so they are never going to meet. :)

Anonymous on Jan 26, 2014
0

Here is the same problem but on a square rather than triangle: http://www.mytechinterviews.com/chasing-dogs

Anonymous on Feb 8, 2014
1

Anonymous on Feb 8, 2014
3

Anonymous on Feb 8, 2014
0

The first inclination is to say that they'll never meet, because it's easy to consider the inside of the triangle off limits, but when answering a quest like this it's important to consider all of the possibilities. You should always ask questions like "Can the ants move on the inside of the triangle?" to get all of the available information. Here's one good example explaining how long and how far the ants would travel: https://www.youtube.com/watch?v=YCWgOsgPYBw

Anonymous on Feb 21, 2014
0

I'm not sure if I understand the question... if it's just ants moving to the midpoint of the triangle -- you could do it geometrically, or if you were given cartesian coords it's even easier. the mid point is the average of the points. so:
mid.x = (x0 + x1 + x2)/3
mid.y = (y0 + y1 + y2)/3
knowing the mid point the distance is simply the distance between the midpoint and any other point. Applying the distance formula:
distance = sqrt((mid.x - p.x)^2 + (mid.y-p.y)^2)

now we have distance, and velocity and we wish to find time. velocity is in units of meters/sec. distance is in meters
we need to solve for seconds. so we divide the distance traveled by the rate, and our units cancel which gives us time.

Anonymous on Sep 28, 2014
2

> I'm not sure if I understand the question... if it's just ants moving to the midpoint of the triangle

Read it again. Each ant moves towards the next ant, not directly towards the center. Their paths describe a spiral arc and they meet at the center eventually, but not via a straight line. Look at the links to solutions.

Anonymous on Sep 28, 2014
0

starting they move to each corner, but as soon as the next ant is getting away from the corner each ant will walk towards that ant, moving in a semicircle, until they reach each other I guess at the center. when they meet? it depends on the velocity and the size of the triangle.

ektormelendez on Jan 25, 2017