25 horses, 5 race tracks. How many races you have to run to select top 5 horses. 58 Answers7 Races First race all 25 in groups for 5 to figure out top 3 in each group. (15 left) Call them A1 B1 C1 D1 E1 A2 B2 C2 D2 E2 A3 B3 C3 D3 E3 Here A1 is faster than A2. A2 is faster than A3. The same applies for the rest of the groups. Now race A1, B1 C1 D1 E1 Lets say the order of the horses according to ranking was A1, B1,C1,D1,E1 So A1 is No 1 Now A1 is faster than B1 and B1 is faster than C1. So we can get rid of the entire D and E groups 9 horses remaining Also A1 is faster than B1 and B1 is faster than C1. So we can get rid of C2 and C3 7 horses remaining A1 is faster than B1. B1 is faster than B2. get rid of B3 6 horses remaining Out of these, We know A1 is the fastest. So now race A2, A3, B1,B2,C1 to figure out No2 and No3 positions Show More Responses because, the top 5 are the fastest right ? so you run one race and take the best five times. It's a trick question to see if you'll make a mountain out of a mole hill. The first question to ask to clarify is: how many horses can fit in one track? Technically, one track can be used for all 25 horses, but this is too crowded for an efficient race. Let's say track size is not a factor, then, you need 1 race. Without overcomplicating things - the answer is 1 race. All other answers are based on dissecting the problem into, imo, unnecessary details. There is no mention of the capacity of each race track or number of gates available etc. Even if there are less than 25 gates available at a track, I'd say fetch enough number of gates so you can find the outcome with single race. This isn't a trick question. Normally this question has a track limit of 5 horses. I agree with Anuradha's answer. Anuradha's solution still has problems. (Even if we go with Anuradha's assumptions that you can only race one horse per track, and also assuming that we don't have a stopwatch and must compare horses placing positions) What if the fastest five horses are A1, B1, C1, D1, and E1 ? In Anuradha's second step, he elminates two of the fastest horses (D1 and E1) . He's assuming that A2, B2, or some of the other horses from the other heats are faster, but he hasn't actually tested to see if that is true. @anuradha: I think there are 2 problems: 1. How do you know A4 is not faster than B1 .... Suppose A1,A2,A3,A4,A5 are the fastest. 2. Using the logic posted we can get the answer in 6 races, 5 races for finding A1,B1,C1,D1,E1 and 1 race to find the ranking. Assuming 1 track for 1 horse then it need 5 races to select top 5 horses. Each race for 5 horses and count the time for each race. The top 5 fastest horses are the top 5 horses. 2 max: top 4 from first race, if 5th is a tie, then two, or else just one. Show More Responses You guys are not doing CS! 10 runs is my answer. 1. randomize 5 groups, each of 5 horses 2. rank them within each group, I will use Anuradha's notation (5 races) 3. pick the best of each group, race to figure the 1st place, call it A1 (1 race) It should be clear, it wins all times, every one lost once. 4. remove it. substitute 2nd best in. repeat 3 (in my eg. A2,B1,C1,D1,E1) now you have second place. keep going, you get the first 5 and ranking! So, 5+5=10 races in total. The answer is 9. Assuming: - There's no time measuring (stopwatch), just relative places. - The horses perform consistently. - A maximum of 5 horses per race. First we need 5 races (A to E) to get relative scores for all 25 horses. Let's take a worst scenario: the list was already ordered (A1 fastest and E5 slowest), so race A contained the top 5. The 6th race would be the winners of the 5 races (A1, B1, C1, D1, E1), and would give A1 as the fastest of all. This would also mean that some horses can be excluded (only 4 more places to fill): B5 C4, C5 D3, D4, D5 E2, E3, E4, E5 For the 7th race, A2 would replace A1, and A2 would be appointed as the runner-up (of all). We also can exclude some more (only 3 more places to fill): B4 C3 D2 E1 For the 8th race, A3 would replace A2, but as E1 has been excluded, we got a vacancy. Let's add C2 for worst case scenario. The winner would be A3, and we can exclude more horses (only 2 more places to fill): B3 C2 D1 At this point there're only 5 horses who have not yet been classified or excluded, so the winner and runner-up of the 9th race would give 4th and 5th overall. To Patrick: I had to slightly modify your almost correct solution and got 10 races. You has an excellent idea to remove subset of candidates after final selection of the i-th horse, and my modifications are not an essential ones. Actually it is necessary to fix two small things: 1. get rid off the suggestion about the ordered list To avoid this suggestion I would rename groups from the fastest A to the slowest E with order by 1st horse after final selection of the i-th horse. So after race #6 we have order: A1, B1, C1, D1, E1, but there is no suggestion that all A are better than all B and so on. And after every race #7, #8, #9 we have to rename groups. With this modification your method works fine until final selection of horse #5 2. Without this suggestion you need race #10 to find the last 5th horse. To test both methods you may use 25 randomly selected integers and select the 5 minimal or maximum ones. I can't prove that 10 is the minimum number of required tests, but it looks very convincing. Thank you. Maybe Ziqi Dai also meant the same method, but it was difficult to understand without a couple of details. To Leo, I checked some random sequences with a spreadsheet, and all the remaining (not placed or excluded) horses run in the 9th race, so there's no need for a 10th race. Sometimes there're only 4 or even 3 horses left in the 9th race. I didn't check every possibility, but there was no indication a 10th was ever necessary. This answer is 1 regardless of track. If it can fit all 25 then you only need one race. If you make the assumption that only 5 can race at a time then you put 5 on each track and start the race on each track at the same time. Either way, the fastest 5 horses win. Using complex math on this is pointless since a pragmatic approach is available. @ Anuradha -- this is a great solution to the wrong problem! The classic problem is to find the THREE fastest, and that's what your solution is. However, the question posed in this thread is (likely incorrectly quoted from the interview) to find the FIVE fastest of the group. why would you make an assumption that makes this more difficult? I mean given this is an IQ test of sorts, making it harder than stated is........ Attention to details, Anuradha! You're answer would've been correct had the question asked for top 3 horses. This is like merge sort. In the first 5 races (when we run 5 horses per race) we get 5 sorted sublists. Each sub-list contains 5 horses sorted by their relative speeds within that sub-list. Now just merge these 5 sorted sublists to get your answer. Every "merge" means 1 race to find the fastest horse from the front of these 5 sorted sublists. To summarize: 1. Creating 5 sorted sublists of 5 horses each = 5 races 2. Getting fastest horse = 1st round of merge = 1 race 3. Getting second horse = 2nd round of merge = 1 more race 4. and so on... Show More Responses Why is this harder than having five races with five horses, recording the times of each horse, and sorting the list of observed values to get the top 3? 7 full explanation; http://www.programmerinterview.com/index.php/puzzles/25-horses-3-fastest-5-races-puzzle/ For 3 fastest horses no doubt the answer is 7 but for 5 fastest I worked it out to be 9. And pretty sure too 1 only if you can do good flow control and horse will start with different time / space out based on best estimate. It is kind of feeding the horse to the gate. Simply 5 races only, i.e. 5 horses in 5 race tracks per race. Finally, select top 5 horses by best fastest timing at finish line after 5 races. As a BA, the answer I would give is: We don't yet have enough information to provide a solution. There is critical information missing that could affect the solution. And flushing out all the critical factors of the problem are one of the most important responsibilities of the BA. As a BA, it is very important to NOT start building solutions to problems that you don't yet fully understand. Actually, it's one of the biggest mistakes inexperienced BAs make: solving the wrong problem because they rushed to solutions and did not fully investigate and understand the problem! Once they're committed to the wrong problem, they end up with a beautifully done inadequate solution. 5 races, because you can fit 5 horses in 1 race and there are 25 horses. You just note the timings of each horse and compare them after all the races are done. That way, you won't have to arrange more than 5 races and stopwatch is a common tool for every phone!!! First of all guys, you guys are making critical mistakes. You assume we have a timer but that would make it too easy, right? I'm just assuming that 5 horses a track and no timer. So I have two potential solutions: 1. You could always just race them all at the same time on 5 tracks...but that'll be too easy. Then there's my solution: --------------------------------------- First, group all the horses into five groups of five. It doesn't matter which horse goes into which group, it honestly doesn't matter. Then, race all the horse in one groups against each other. It helps to name them A-E(Group name) and the number place they came in (ex: 1st place a group would be A1). So now we have A1 to A5 and B1 to B5 and so on until E5. Then race all the 1s against each other. You should get something like A1, C1, B1, E1, D1 and then you should arrange their groups in collumns from left to right based on that race (1st on left, 5th on right). Here is where it starts getting complicated, so I will just assume it is A1 fastest in that race and E1 slowest and so on just for simplicity. So so far this is 6 races. Get E1 and race them against D2-5. You can ignore E2-5 because no matter what they can never be in the top 5 because A1, B1, C1, and D1 is the fastest of their groups and you know that the fastest five can come from those groups but not E2-5 because E1 is the slowest of the 1's and there's no way those horses can be in the top five. SO just throw them away. Since there are four spots available max you race the slowest four of the D which happens to be D2-5. Get the place numbers and arrange them. EX: D1 D2 E1 D3 D4 --- D5 E1 can be anywhere based on E1's speed but you immediately want to discard the D5. You might be saying, "Hey, why can't we discard anything below D2 since A1 and B1 and C1 are all faster than D1 and E1?" But...you could be unlucky and have A2-5 and B2-5 and C2-5 be all dirt slow. So just keep them for now. So the rule now is to keep all the horses that are in the top 5 and discard the rest until you get to A, when you know, "Oh, A1 has to be the fastest horse." 7 races. So we have our list above just for examples. Next you want to race D4 against C5 to see if our group can EVEN pass the C's, cause we might get super unlucky and see that C1-5 is faster than D1...if D4 loses in 5th place we just throw this all away and our new list becomes: C1 C2 C3 C4 C5 But otherwise we'll just assume that our D4 luckily got to 3rd place. It becomes: C1 - Our group can go anywhere inside the lines so race them again C2 minus D4 since its in 3rd place to see where they go. Let's assume we got SUPER lucky and C2 became last place in that race. - C3 C4 C5 8 races. We raced this group at that time and left out D4 because D4's fate was already decided: D1 D2 E1 D3 C2 It turnes into this: C1 - D1 D2 The single dash indicates where our new group was spliced, ofc the triple E1 dash lines show where the cutoff is, so discard everything under the line. D3 -(---) C2 D4 C5 9 races. Kay, so now we have the five fastest in the E, D, and C groups. Now continue with the B groups and let's say that our D3 passed B4 only... It becomes: B1 B2 - With our top five so far group racing against B4 B3 - D3 B4 B5 10 races. And then with another race you get this with lets say...only our top two making it through with B3 getting ironically first place: B1 B2 B3 C1 D1 --- D2 E1 Yep...E1 got kicked out. Aw well. SO NOW our to group D3 is the group above the triple dash marks. B4 B5 11 races. Now we're up against the A group. Assume that they are all wusses and that our D2 beat all of them except for A1. So we got lucky and the new lineup is this: A1 B1 B2 B3 C1 --- It was inevitable that A1 would become first but now this is how you do it! D1 D2 A2 A3 A4 A5 12 races/13 if our B1 didn't beat all of the other A's on the first try. Conclusion: 5 races (initial races)+1 race(for initial group leader ranking)+1 races(E-->D)+2 races(D-->C)+2 races(C-->B)+2 races(B-->A) =13 races/10 races if you get insanely lucky and have all our previous groups beat all the #2s of the groups. Show More Responses Oh nvm ignore that it was all crushed into one place with no spaces...I'll stick a better one later. The answer is 8 races assuming that you can fit only one horse on one track. Divide the group into 5 horses. In five races we can find the 5 fastest horses in the 5 groups. The 6th race is among the top 5 fastest horses. The top three fastest horses in the 6th race are faster than the horses in the group of the 4th and the 5th fastest horse. The horse that came third in the 6th race may or may not be faster that the horses in the group of the fastest and the send fastest horse. To determine that, we hold 2 more races. So 6+2 = 8 races is what I think is the correct answer ****************ANSWER -- 3 RACES.************* Given : 25 horses, 5 tracks Assuming : 5 horses to a track Five groups of 5 horses for each track (5 tracks, tracks ABCDE, each track with horses labeled "X#") First race allows you to find out the top 5 horses (however this isnt the true top 5) [A1,B1,C1,D1,E1] Second race the top horse is discovered (lets say its A1) Now you have to find out if B1 is better than A2, B2 is better than C1, etc. (each predecessor of each winner) We know that B1 is better than [(CDE)1] Third race we have A2,B1,B2,C1,D1 Conclusion : If both of the predecessors are NOT last place, then we have our answer at race 3 by taking the top 4 to be the bottom 4 of the top 5. Otherwise, repeat this process one more time to find the 5th placed horse. Patrick gets the right number but his logic is not the most efficient. Initially follow the standard procedure and race 5 groups of 5 (races 1-5) and then race the winners (race 6). The winner is the fastest overall. Now name the groups with the horses in the winners group A1,A2,A3,A4,A5, the first four horses in the runner-ups group B2,B3,B4,B5, the first three horses in the third group C3, C4, C5 down to E5 for the winning horse from the slowest group. The numbers indicate the highest possible position a horse could attain (i.e. C4 is definitely slower than C3, B2 and A1 but may be slower than several others). The rest of the horses are eliminated and so don't need to be labeled. Now race (race 7) the horses labeled 2 or 3 (there are 5 - A2,A3, B2, B3, C3) The top two are second and third overall and the loser is eliminated. You can eliminate a total of 5 or 6 horses - those known to be slower than the fourth or fifth place finisher and any two positions slower than the third place finisher in race 7. There aren't that many options here so you can just inventory all the possibilities if you wish. At this point you have a maximum of 7 horses for the remaining two positions You just race any 5 (race 8) to eliminate at least 3 and race the rest (race 9) to get the fourth and fifth fastest overall. If you choose all the potential fourth place finishers in race you may not need race 9. As noted elsewhere Anuradha gets the right answer to a different question than the one asked. I have stepped among a lot of smart folks here. Maybe even several analyst's. So here it goes. I am looking at this as who the question is coming from and for what. A Business Operations Analyst for Google. Everyone is so focused on answering the question based on assumptions. Ie. That every horse and rider are at their best condition and that every track is exactly the same. That you are running all the races in the same day and that horses, riders, and tracks dont change. Horses and riders get tired, not to mention the possibility of injuries, and track conditions can change so forth and so on. So to me. In order to (analyze) to get the best possible answer. I would start by asking questions and not assuming. The more information you have leads to the best possible answer. Guys think as a programmer, (mind my language and grammar) algorithm would be of these steps ->group the horses (5 horses each) -> get the best runner of each group (five races) -> store the horses in winning orders to five stacks (a,b,c,d,e) ->until the top 5 are found, repeat ->race all the 5 on top of the stack ->pop the winner from its stack and store in top five that all, now lets see how it will work. lets have 5 horses per group and group them as a,b,c,d,e. 1=a1 a2 a3 a4 a5 a1 (winner) 2=b1 b2 b3 b4 b5 b1 3=c1 c2 c3 c4 c5 c1 4=d1 d2 d3 d4 d5 d1 5=e1 e2 e3 e4 e5 e1 now we have best of each group, let them race 6=a1 b1 c1 d1 e1 a1 for every winner get the best candidate for the group, and race again, until top 5 are found 7=a2 b1 c1 d1 e1 a2 8=a3 b1 c1 d1 e1 a3 9=a4 b1 c1 d1 e1 a4 10.a5 b1 c1 d1 e1 a5 for any scenario just get the so the ten races. its like finding five highest numbers from 25 numbers, when you can only compare 5 at a time. Answer- 7 Races Give names H1....H25 Divide into 5 groups as 5 can run at a time H1, H6 , H11, H16, H21 are fastest in there groups Now we can remove last two from each groups as we need fastest 3 now we left with 15 horses 6th Race- between all fastest in groups After 6th Race H1> H6 > H11> H16,>H21 Now H21 was fastest in group but is 5th in 6th race so H22 and H23 who already slower than H21 can't be in first 3 Same thing applied for H17 and H18 as H16 was fastest in group race but 4th in 6th race Same applied for H12 and H13 as H11 was fastest in group race but 3rd in 6th race Already three horses are faster than H16 and H21 so they both also can be rules out Now we left with H1, H2, H3,H6, H7, H8 and H11 But H8 is slower than H7 and H7 is slower than H6 in group race and we have H1 on top already so H8 also can't be in fastest 3 Now we left with H1, H2, H3,H6, H7, H11 H1 we know is fastest..so lets 7th race between H2, H3, H6, H7 and H11 and find the other two After 7th race you will get fastest 3 Make a group of 5 horses per track and race them all at once. The winners of each track totals to "the top 5" ! The answer is 7. Assuming: - There's no time measuring (stopwatch), just relative places. - The horses perform consistently. - A maximum of 5 horses per race. Race r1: A1 A2 A3 A4 A5 (By order of winners) Race r2: B1 B2 B3 B4 B5 Race r3: C1 C2 C3 C4 C5 Race r4: D1 D2 D3 D4 D5 Race r5: E1 E2 E3 E4 E5 Race r6: A1 B1 C1 D1 E1 (rename R1 R2 R3 R4 R5) Here comes the tricky race. From race 6, we already know the ranks. As a demonstration, assume R1 = A1, R2 = B1, R3 = C1, R4 = D1, R5 = E1. Then: 1) D1 D2 D3 D4 D5, E1 E2 E3 E4 E5 are out of the contest. Because D1 and E1 are ranked 4th and 5th in a race. 2) C2 C3 C4 C5 are out of the contest. Because two horses already are faster than C1 ==> 3 horses are already faster than C2 C3 C4 C5. 3) B3 B4 B5 are out of the contest. Because one horse already faster than B1 ==> 3 horses already faster than B3 B4 B5. Remaining potential horses are: A1 A2 A3 B1 B2 C1. Here, A1 is redundant because we already know it is fastest. Race 7: A2 A3 B1 B2 C1. The top 2 will be added to A1 to be the fastest three. Show More Responses Take a look at previous horse race statistics from horse newspapers. Make your analytic and you have your top 5 horses without any new race :) It will take min 9 race not 7: first five race and find top 3 @ every slot now total race=5; one race between first five, now we find top 3 and take 2nd and 3rd from the race as 1st is declared. race=1; 1 race between 2nd finisher of all slot and take 2 from them , race=1; 1 race between 3rd finisher of all slot and take top finisher, race=1; now we have race between 5 horses(2+2+1) and find 2nd and 3rd; so total no of races= 5+1+1+1+1=9 ; I have grouped them in 5 groups. See the groups below. I have also ranked them in the order of the wins. So for e.g. in the first group, 1st horse came first, 2nd horse came second and so on In the second group 6th horse came first, 7th horse came second and so on. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 After the first five races, there will be two more races So the sixth race will be among the horses below (who were first in the previous races) and I have ranked them in the same order in the 6th race 1 6 11 16 21 - - So 1st horse came first, 6th horse came second and so on. Now for the 7th race, we will take the winner of the 5th race and make him compete against the first four winners of the 6 the race. So it will be something like this and I ranked them in the same order for the 7th race. 1 6 11 16 26 - So from 7 races it will is very clear that the fastest four horses are 1 6 11 16. Now, only 21 and 26 are the contenders for the fifth position, based on their timings in their respective races (6th and 7th ones), we can decide which one is faster between the two. So in total , we would need 7 races. The question is not a good one! Let those horses be marked X1~X25. First divide them into 5 groups X1~X5, X6~X10, .... Assume the first X1, X6, X11, X16, X21 are the fast ones in each group after the first round. Also, X2 > X3, X6>X7, during the first round. We then, during the 2nd round, form the first group with those fastest from each group in the first round. Assuming that X1 > X6 > X11 > X16 > X21 after the first try of the 2nd round, we will then have X2, X3, X6, X7, X11 to form a new group and determine which are fastest 2 in this new group. Nevertheless, during the 2nd try of 2nd round, it can happen that X3 > X2 or X11 > X6. The inference fails all the relation set in the previous try. ( that the X2 > X3 ,after the first round, and X6 > X11, after the first try of 2nd round). It would be better to change all those horses to be boxes carrying different integer value. You want to sort those boxes to find which carrying the largest 3 numbers and, at any time, you can only open 5 boxes to inspect . You cannot mark the content of boxes but you can put down the relation between boxes during the inspection. Then, the number of inspections needed to find boxes with the largest 3 number will be 7# This seems like a simple answer, but I'm pretty sure it's 9. Race 5 groups of 5, then race all the 3rd place, then the winning 3rd races the seconds, then you have either have five firsts and two seconds left or 5 firsts a second and a third left from the original racing groups. Worst case scenario you have one more race of three ones and two twos or two ones and the 2nd and third place to find the fastest there out of that last group. 9 races. So driving down the road I figured out I should have started from the top after the first five races. Then worst case scenario you run three more races to find out the top three. 11111, 21111, 31111. Damn. Six races, six groups. First group will have five horses, the 5 others groups will have only 4 horses. The winner of the first group of 5 horses will pass to the second race, then the winner of the second race will pass to the third race and so on, bay the end of the 6 race you will have top 5 horses. 25 horses, 5 race tracks. How many races you have to run to select top 5 horses. Solution: http://codinginterviewquestionsans.blogspot.in/2017/07/25-horses-5-tracks-5-fastest-horses.html Step 1: First, we group the horses into groups of 5 and race each group in the race course. This gives us 5 races. W11 W12 W13 W14 W15 W21 W22 W23 W24 W25 W31 W32 W33 W34 W35 W41 W42 W43 W44 W45 W51 W52 W53 W54 W55 Step 2:we race the 5 level 1 winners(w11,w21,w31,w41,w51) and assume winning order of this race is w11,w21,w31,w41,w51 (THIS IS 6TH RACE) Step 3: BECAUSE WE NEED TOP 5 AND W51 HAS COME 5TH Position that is the reason we don't need to consider W52 W53 W54 W55 now we have W11 W12 W13 W14 W15 W21 W22 W23 W24 W25 W31 W32 W33 W34 W35 W41 W42 W43 W44 W45 W51 Step 4: because we need top 5 then dont need W25 W34 W35 W43 W44 W45 now we have W11 W12 W13 W14 W15 W21 W22 W23 W24 W31 W32 W33 W41 W42 W51 Step 5: top 1 is already achieved which is W11(winner of 6th race) remaining are X W12 W13 W14 W15 W21 W22 W23 W24 W31 W32 W33 W41 W42 W51 Step 6: candidates for 5th position: W51 W42 W33 W24 W15. 1 RACE TO GET 5TH POSITION (this is 7th race) remaining are X W12 W13 W14 W21 W22 W23 W31 W32 W41 Step 7: candidates for 4th position: W41 W32 W23 W14. 1 race to get 4th position ((this is 8th race) X W12 W13 W21 W22 W31 Step 8: candidates for 2nd and 3rd position: W12 W13 W21 W22 W31. 1 race to get 2nd and 3rd position ((this is 9th race) Hence answer is 9 races. Assuming no limit to how many horses on a track, 1, because the fastest 5 will obviously finish in 1st, second, third, fourth, and fifth place. If there is a limit to the number of horses on a track, then it will take (25/number of horses to a track) rounded up to the next integer races because you can just compare the times of all of the horses and pick out the five fastest times. There are a lot of wrong answers on here or answers for different questions. Answer for top 5 is 8 races. You can find explanations online for this. Show More Responses Friends only 5 races are required As mentioned we have 5 tracks and 25 horses. So divide them into set of 5 And winner of each set is fastest so only 5 races are required. If there in no limit on track one race is enough. But if 5 horses can run at a time we need 6 races. 5 races to find top of each group. And additional 1 race among those top 5 horses to find out top 3. answer is 8 suppose we have limit of 5 horses per track and all horses run together on 5 track so *-5 races-* conducting on five track, the top one of each track is selected for further race and now race is conducting between the all top 5 horses which is *-6th race-* and the remaining 4 horses will race again for 2nd and 3rd position hence total no. of race are 5(all five races)+1(6th race)+1(7th race)+1(8th race). So many wrong answers here, first of all the question is about FIVE fastest horses, not three, so all the posts giving 7 as an answer are wrong. All the answers above 9 are also wrong. You need 7 races to find 3 fastest horses, after that by using logic you come down to either 6 or 7 remaining horses as candidates for places 4-5, and you need 2 races to figure out which 2 of them are the fastest. So it's 9 races in total. |