Tuesday, January 4, 2011

Another Interview Question

This is an interview question for software engineer position at USAA:

"A train leaves San Antonio for Houston at 60 mph. Another train leaves Houston for San Antonio at 80 mph.  Houston and San Antonio are 300 miles apart.  If a bird leaves San Antonio at 100 mph, and turns around and flies back once it reaches the Houston train, and continues to fly between the two, how far will it have flown when they collide?"

First, we need to draw a line to analyze this:

|<------------------------- 300 ------------------------------|
SA                                                            H
 --------60------->             <--------80 ------------------|                            

When these two trains collide, the distance between them is d = 0, or 60*t = 300 - 80*t, solving this equation we get t  = 300/140  hours = 15/7 = 2.143 hours. Meanwhile, for the bird the equation is: 100*t = 300 - 80*t, or t = 300/180 = 1.667 hours.  This is the time when the bird reaches Houston train and turns around.  How far it has traveled from SA? 100*1.667 = 166.7 miles.  For this duration, SA train has traveled 60*1.667 = 100.02 miles toward Houston.  The distance between the bird (now flying back toward SA) and SA train is = 166.7 - 100.02 = 66.68 miles.  How many minutes before the bird hits the SA train? We use the similar equation:

|<------------------------- 66.68 ------------------------------|
SA                                                            H
 --------60------->             <--------100 -------------------|

Or, 60*T = 66.68 - 100*T T = 66.68/160 = 0.41675 hours. Total travel time for the bird: t + T = 1.667 + 0.41675 = 2.08375 hours (and it occurs before these two trains collide each other).  Total travel distance for the bird: 100 mph * 2.08375 hours = 208.375 miles


  1. I don't think this has answered the question posed. The bird is supposed to fly back and forth multiple times, until the trains collide. The answer posted covers only the first two legs. Here is a shortcut - the combined speed of the trains is 140 mph, so they will collide in (300/140) or 2 1/7 hours. In that time the bird will have flown 100 * (2 1/7) miles or about 214.2857 miles, ignoring relativity, and assuming the bird maintains a constant speed during the whole process.

  2. Thanks for the clarification.

  3. If I were to answer the question, I would point out that there are ambiguous pronouns that prevent me from providing a definitive answer. Does "two" refer to the two trains or between the Houston originating train and San Antonio? Does "they" refer to the bird and the San Antonio originating train or to the bird and both trains?

    Anyway, if pushed for an answer, mine would have been the same as Doug's.