Amazon Interview Question for Software Engineer in Tests






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

6 trials for fastest horse and 7 for second fastest

- Anonymous April 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why to go for 7th trial for second fastest. Which ever horse will come second in 6th Trial is second fastest...

- Anonymous April 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

its possible that second fastest in race 6th is slower than the horse 2nd to the fasted horse

- Anonymous April 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey consider this case - We are splitting 25 horses into groups of 5 and conducting 5 trials. What if the second fastest among 1st group is the fastest compared with the fastest horses of other groups?? So for the final trial even if we conduct only among the fastest of all the groups we are likely to miss the second fastest one which is still in the 1st group. Hence I think we might need to remove the fastest horse from its initial group. Conduct a test among its group of 4. Then conduct the fastest among all groups. So 5+1+1+1 trials might be required. Corrections are welcome!!

- Sriram April 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Oops we can do it in 7 trials itself by noting down the second fastest of initial 5 trails in the first itself instead of conducting one more trial

- Sriram April 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Lets say we segregate the horses in 5 groups - A, B, C, D and E. We conduct 5 races and we get the winners in each of the category. Let them be A1, B1, C1, D1, E1.

Now we conduct a race between the first horses from each of the 5 categories. The winner is the fastest.

To find the second fastest, we need to see which are all the eligible ones. Lets work on an elimination concept for this. The horses that could come second are - B1, A2, A3.

We eliminate C1,C2.., D1, D2.. E1, E2.. etc because B1 is faster than C1 and C1 is faster than C2, C3 etc. Similar concept applied to groups D and E.

The race among B1, A2, A3 would give the second fastest horse.

Total number of races = 7

- Anonymous May 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

For the second fastest horse, why you consider only B1,A2,A3?

We know A1 is faster than A2 and if A2 is faster than A3, then racing only B1 and A2 will suffice.

If we are not sure whether A2 is faster than A3, then we have to consider A4,A5 also.. Because we know only the facts that A1 is faster than A2,A3,A4,A5 and B1 is faster than B2,B3,B4,B5 and A1 is faster than B1. We can't determine which is faster among A2,A3,A4,A5 and B1

Correct me if I am wrong..

- Anonymous May 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We dont have a stop watch here !!!!!!!!!!!
There is no way to determine that B1 is faster than C1 OR D1 OR E1. Without a stopwatch, in every race we have knowledge on the positions of the horse at the end of the race but not the speed.

So we cannot compare the horses across races directly. Only medium to compare is through a race :).

- Sudhindra May 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Sudhindra: He already assumed that after 6th race, A1 > B1>...E1.

- yurongzhen December 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Can be done in only 4 races ....

Race [1]
Make 5 hourses run from one direction and another 5 from another direction, and also mark the middle point of the race...
Notice first 3 intersections of the hourses and select the hourses who crossed their first half mark as the 3 fastest...
Race [2] repeat this with another 10 hourses

Now we have 6 best hourses and 5 untested
Race [3] Make 4 hourses run from each direction and choose the 3 same as above
Now we have left with 6 hourses
Race [4] Make 3 hourses from each side run and choose the best 3....
Done in 4 races

- Ashupriya June 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good one.
Its the first time I hear about running two horses in the same track :)

- sathishp123 November 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Sriram : Your first concern was actually valid. Your second comment is invalid because you cant note down the second fastest as you are not given a stopwatch.

- Sudhindra May 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@sudhindra: why do we need stopwatch to know the second fastest, the way we know which is first in race-1, the same way we know which came second also. Here why stopwatch ?

- nomad August 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think of it as as function getMax with 5 parameters
function getMax(Horse []horse) // takes 5 horse parameters
{
//returns fastest horse
}

1. Creat 5 groups
2. call function 5 times for each 5 horse group
3. you have 5 fastest horse now
4. call function again with this 5 horses
5. you have the fastest horse now (total calls 5)
6. eliminate fastest horse and call function again with rest of 4 horses
7. you get the second fastest (total calls 5+1=6)

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

correction:
4th step - total calls is 6
7th step - total calls is 7

- Anonymous May 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

7 is not correct

Example:
In group one, out of 5 two horses have speed 50 and 60 units/hour.
And the highest speed in all other groups is 40. The race will be with horse with speed of 60 and 4 horses with speed of 40. 60 is the winner but the second fastest is not 40 but it is the horses with speed 50.

Correct solution is to eliminate fastest horse and take the second fastest from the group to which the fastest horse belong and make the five race.

- Adi June 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

7 is correct but not with the logic of racing four horses.

- Adi June 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

yups 7 is the answer

- Anonymous May 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let {A1,B1,C1,D1,E1} be the winners of 5 groups {A,B,C,D,E}
and {A2,B2,C2,D2,E2} be the runner ups of 5 groups
This would take 5 races
6th race among {A1,B1,C1,D1,E1} would give us the fastest horse.
Let C1 be the runner up in this race.
Now the eligible candidates for runner up position are {A2,B2,C2,D2,E2} and C1 as well
We conduct 7th race between {A2,B2,C2,D2,E2}
Let D2 be the winner of 7th race
Now we make C1 and D2 run in 8th race.
The winner of 8th race is the 2nd fastest of all.

Please suggest if there is any other better alternate...

- Tejas Desai June 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adding to this: It is possible to find the top 3 horses in 7 rounds itself.

- sathishp123 June 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ans-7
Divide the horses into 5 groups(A,B,C,D,E).Now find the fastest and second fastest in each group(A1,A2,B1,B2,C1,C2,D1,D2,E1,E2).Now find the fastest among all by the race among top 5 fastest(A1,B1,C1,D1,E1).We can get the fastest from here.Now for the second
fastest conduct a race between the winner's group 2nd fastest and all other group fastest.winner of this race would be the second fastest horse.
like-suppose winner is C1 the conduct a race between A1,B1,C2,D1,E1.so winner of this race is second fastest.

- shobhit June 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes its 7
Get the fastest in 6 races, that's clear. Also record the 2nd of each race. Now for 2nd fastest just race the 2nd from the 6th race with the 2nd from the group containing the fastest horse, that should do it.

- Zodiac July 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

7 Trials is the correct answer I guess!
*Split the 25 horses into 5 groups a,b,c,d,e.
*Note down the top 2 positions in each group. Let them be a1,a2,b1,b2 etc.
*Now we know that the fastest horse is one of these <a1,b1,c1,d1,e1>
*To find the second fastest. Pick the second fastest horse from the group, from which the first horse was picked. i.e
- If a1 was picked then pick a2. If b1 then b2
*Now test this horse against the fastest horses of the other groups. i.e if a1 was picked then conduct a race between a2,b1,c1,d1 and e1. Else if b1 was picked then conduct a race between a1,b2,c1,d1 and e1

- Deepak August 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

there may be chance b1>a2 , then it will be more rounds right?

- Rayap November 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

This is my solution : 8 Rounds
I will split 25 horses into 5 groups, each group having 5 horses. For each group, i will track 1st and 2nd fastest horses. This will take 5 rounds.

I will arrange a race for first fastest horses in the 6th round. I get the fastest horse among all 25 horses. But i will track the second fastest horse in this round as well.

In 7th round, there will be a race of all second fastest horses. I will track the fastest horse here.

In 8th round, there will be a race between 6th second fastest and 7th fastest horse. Fastest horse here would be the second fastest among all the 25 horses.

- Sudhindra May 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why 8 rounds...
just make 5 groups from 25 horses.
and race them ...there will be 5 winners ...from each group
That will ensure that we have the best from all the 5 lots.
Now 6th race for the best among the best ..and also we will get the fastest as well as the second fastest...ie the number 1 and number 2 posistion holder...

- GS May 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

GS : You are missing a scenario. For example, second fastest horse in the first group may run faster than the fastest horses among all other groups.

- Sudhindra May 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

In your 7th round, you only need to race the second fastest in 6th round and the second fastest to the best one of 25 horses which was noted in one of the first 5 rounds.

- yurongzhen December 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

8 is the correct answer...7 is wrong

- surya August 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

trial 1 : a1>b1>c1>d1>e1
trial 2 : a2>b2>c2>d2>e2
trial 3 : a3>b3>c3>d3>e3
trial 4 : a4>b4>c4>d4>e4
trial 5 : a5>b5>c5>d5>e5
trial 6 : a1>a2>a3>a4>a5

this means a1>a2 which is faster than b2 and [b2>c2>d2>e2] as per trial 2
a1>a3 which is greater than [b3>c3>d3>e3] as per trail 3
..........

so a2 is second fastest ..


What say ? Everyone :)

- Phoenix November 03, 2011 | 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