Google Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
7
of 7 vote

Lets assume the the radius of the pond is R
and max speed of duck in water is v
and max speed of fox on land is 4v.

Lets d is distance for duck to reach the edge and assume the fox is on exactly opposite side on the circle.

d/v will be time taken by duck to reach edge whereas
pi*R/4v will be time taken by fox to reach the same point

For duck to reach safely at edge d/v <= pi*R/4v
that is d <= (pi/4)*R

If duck starts circling in the pond exactly at distance d1
then 2*pi*d1/v <= 2*R/4v
therefore the duck should start circling at d1 radius = R/4.

Now if duck reduces the circling radius even slightly, the possibility of living fox behind will increase. When the fox and duck are exactly opposite, the duck can start swimming towards edge. Now, the remaining distance to edge is (3/4) R.

as the remaining distance is (3/4)R is lesser then (pi/4)R. The duck can reach edge safely and fly.



For duck to start swimming towards edge from a point is d distance from Edge and assume the fox is exactly opposite t

- Anonymous September 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I have one solution and think it is the best one.
/////////////////////////////////////////////////////////////////
Fox speed 4v, duck speed v.
/////////////////////////////////////////////////////////////////
First, of course the duck won't swim to the fox. So duck will swim to the opposite.

From then on, the speed of duck can be divided into two speeds: one is opposite to the fox, one is to the edge. That is, the duck will keep its position, the center of the pond, and the position of current fox at the same line. Duck and fox are on two sides of the center. And the other speed of duck is used to move to the edge.
When the position of duck is R/4 to the center of the pond, duck's speed that used to keep fox and the center of pond in a line is v. Because: fox to the center of the pond is still R, and its speed is 4v; duck to the center of the pond is R/4, speed is v.
R/4v == (R/4)/v. At this time, duck's speed used to move to the edge of pond is 0. So the duck will change its method and use all it effort to swim to the edge. The speed is v.
Now, the edge to duck is 3R/4. Fox to this point of the edge is pi*R. So duck needs 3R/(4v) to go to the edge, while fox needs pi*R/(4v).
Since 3<pi, so the duck can get to the edge before the fox.

Sorry for my English.

- sunbow.xs@hotmail.com September 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Given that the duck is in the middle of the pond, if he goes under the water, splashing in one direction, but moving in the opposite, the fox pursues one way around the pond. All the duck has to do is persuade the fox to go the longer way around the pond for a moment, and the duck will be ahead just enough to take off. One more comment, can the duck be in the air (assuming the fox cannot eat the duck out of the air) directly when he hits land?

- OR September 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

please explain

- balajee September 24, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i really dont think that duck can cross the pond safely . actually as fox goes 4 times faster than duck .. as duck is in the middle . the minimum distance to touch the land is suppose R .. and it takes T time to reach thr . (worst situation for fox ) then the fox can travel 4R in the same time which is greater than pi * R . Running always in opposite direction doesnt make sense . moreover more nearer the duck to the land . more predictable for fox to catch the duck. .@OR u cant cheat fox by splashing in one direction. Remember fox and duck will take optimum move

- backtolife September 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

From the problem: "...Assuming the fox and duck pursue optimum strategies..." I think it means that fox can change directions

- Victor September 25, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Victor,

I hope I've understood your question. Here is my explanation. As long as the duck is within r/4 distance from the center of the pond, it is radially faster than the fox. Therefore it can cover radially more distance than the fox. So radially, the duck will go as far as possible from the fox. At some point duck will be exactly on the opposite side of the fox (Imagine a straight line between the duck and the fox). This is true even if the fox switches the directions at any point. The duck will then switch direction and go straight along the radius. The duck has to cover 3r/4 distance. Even if the fox covers four times 3r/4 which is 3r, it still lags behind the duck. Because the fox has to cover pi * r (as it is in the opposite direction) distance to get the duck.

- sppl September 28, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

spol.pl
Your solution assumes that the duck can reach a point which is r/4 from the edge while the fox is at the opposite edge (on the line connecting the center and the duck). Since the fox uses optimal strategy as well, it can always move so that it is not at such a point. (so distance to be covered by fox is less than pi*r)

- Metta September 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes that is possible. But the duck can switch directions too when the fox does. And moreover it is faster than the fox radially when it is within R/4 distance from the center of the pond. This makes it possible for the duck to reach the point when the fox is on the other side.

- Anonymous October 04, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the fox will always be able to catch the duck.
Reasoning : R - radius of pond, V - velocity of duck
Assuming duck is in the center of the pond, it will have to travel distance R from center to the edge. So duck will take R/V seconds to reach to the edge.
Fox will have to cross half the circumference i.e. pi * R distance. Hence it will take (pi * R)/4V seconds to travel. Comparing the duration of both the animals, (pi * 4 ) < 1, hence fox will always take less time to reach the edge than compared to the duck.

- Anonymous March 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Pls Read the other answers and try to understand them. Many of them've given the right answer. Duck can Escape.

- VK July 07, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the duck can never escape. The answer of "anonymous" is right with only a little typo at the end (i.e., pi/4<1).

- anynympous July 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL!

Just saying it again and again won't make it right.

This is a classic puzzle. The min ratio of fox/duck speed at which the duck is caught is ~4.61. So in this case, when ratio is 4, the duck _can escape_.

The actual threshold value is the max value of a for which

pi + arc cos(1/a) - a * sqrt(a^2 -1) < 0

which comes to 4.60333884875170...

If you are still not convinced, search the web.

- LOLer July 10, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Duck can escape the fox. The duck should take a spiral path from center.when it reaches a point where fox is exactly opposite and the distance to the land is r such that r/duck_speed < pi*R/fox_speed

- Maankutti August 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not sure of the spiral logic, I guess the duck cannot escape the fox..
Lets assume speed of fox is 4s and of duck as s
The duck is in center of the pond. The maximum distance duck has to cover to move in opposite direction is radius(r) of the pond. Where as for the fox is half the circumference(22/7 * r)..lets calculate the time taken by both duck and fox..
For fox it takes (3.14*r/4s) =0.76*r/s seconds, For fox it takes r/s seconds....
From this its obvious that fox takes lesser time before the duck reaches the edge of the pond...

- T October 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

T, try some coffee, then search the web.

- LOLer October 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL has it correct, and it is OBVIOUS - those who say that the fox will win if the duck makes a mad dash for the side from the center (t=R/v) are correct of course, but open your mind a fraction... the duck moves to R/4 from center, maneuvers to get himself opposite the fox (easy) and only then makes a mad dash for the edge. Disagreeing only shows you have blinkers on.

- Steve March 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Okay,

1) If the duck moves .25 away from the center, it can circumnavigate the mid-point at the same speed as the fox. Note: it does not _travel_ at the same speed as the fox, it _circumnavigates_the_center_ at the same speed. ie. the radius of the circle travelled by the duck is 1/4 the radius of the circle travelled by the fox.

2) Thus, if the duck starts circling at any point less than 1/4 from the midpoint, it circumnavigates faster than the fox and will eventually be directly opposite the midpoint from the fox.

3) Let's say that the duck starts at .22 from the midpoint and circles until it is opposite the mid-point from the fox. The duck is now .78 away from the point on the shore that is directly opposite from the fox. The fox will have to travel 3.14159... (following the shore) to reach this point.

4) By the time the duck reaches that point, the fox will only have traveled .78 x 4 = 3.12 around the shore

5) Thus, the fox will be .02159... away from the duck by the time it reaches the shore.

- Anonymous September 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Waite for sundown. Swim quietly

- Basie January 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

chutyaa banana bandh kar lavdu

- Anonymous June 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes, this is possible for the duck to escape and the duck should use the singularity when it and the fox are both on the diameter line of the circle.

The optimal strategy for the fox is as follows
(assuming both fox and duck can accelerate to their maximum speed and stop instantly):

1. When the duck is on the diameter line from fox to center of pond:
a. If the duck is between the center and the fox - don't move
b. If the duck is behind the center - move around the pond (to either side).

2. If the duck is not on the diameter line from fox to center of the pond - move to the corresponding side which is closer to the duck.

Now the duck's task is to swim further and further away from the fox, while avoiding fox to switch direction of its run.

Beginning: duck in the centre, fox doesn't move.

Duck starts moving away from the fox.
Fox starts moving around the pond, say, to the right.
Duck keeps moving away from the centre and more and more to the left in a spiral movement, while keeping the angle fox-center-duck always slightly less than 180 degrees.
In this situation the fox will continue running in the same direction, the duck will go further and further away from the center while staying nearly opposite to the fox.
When the duck reaches the edge of the pond, the fox will be nearly on the other side.

(By the way: even if the fox will switch the direction, it will not help him, as the duck will always be able to maintain the angle close to 180 degrees)

- leonid.ge July 31, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

yes, the duck go to the opposite direction at each time point.

- chuncl September 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Define a 'moment'?

- moment? September 20, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

By 'moment' I mean 'time point'.

- oops September 20, 2008 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More