7 million views! Thank you! Here's a Microsoft interview puzzle I think you will enjoy. A cat is hiding in one of five boxes that are lined up in a row. The boxes are numbered 1 to 5. Each night the cat hides in an adjacent box, exactly one number away. Each morning you can open a single box to try to find the cat. Can you win this game of hide and seek? What is your strategy to find the cat? What if there are n boxes? Watch the video for the solution! th-cam.com/video/yZyx9gHhRXM/w-d-xo.html
I know this is a little bit late but i got a different result and i want to know if it is right. My result was 6,because that in the same race that we used to discover the first fastest horse we could use to discover the second and third fastest horse. Sorry if it is hard to understand, it's because i'm not english.
@@MrJelle18 I was saying that,in the race that we discovered the fastest one,we could say that the second and third place would be the second and third fastest horses.
Depends on the race. Run them through an Army obstacle course. I'm guessing they'll get hung up on the wall climbing, rope swinging and belly crawl parts. It also depends on the length of the race. Native American runners could outrun horses in an endurance race. People are willing to keep going when animals would quit. So, if you're in shape for a marathon, you'll probably win.
@@flatebo1 Humans have an innate advantage in an endurance race vs most animals our species evolved to hunt critters by running them to exhaustion, that is to say we are naturally built for persistence hunting.
@@seraphina985 have you ever rode a horse? He is really enduring, why do you think he was used as a transport mean in the past? Even if its an endurance race he will leave a long distance with the human so he he could rest and start again, but don't worry he will not get tired before minimum 5 hours
what i dont get is why we need 7 races : we must do five races for the five groups and from that we have found the 5 fastest horses of them all secondly we just race those five horses and the first three to finish are the fastest three horses right ? so that a total of 6 races ! P.S : no where in the question does it state that you need to know their ranking aka whos fastest of the three ...
@@shadi3993 But if the 3 fastest horses are in the same group your method will only identify one of them. Here is how you can really solve this problem with 6 races: Let 5 horses race and label the 3 fastest horses from that group A, B, C. Assume that C is the 3rd fastest horse of all 25 horses and proove that by letting C race against the remaining 20 horses with 5 more races (6 in total by now). In the unlikely case that C is indeed the 3rd fastest horse, you've identified the 3 fastest horses (A, B, C) with 6 races. This is'nt an efficent method because it requires more than 7 races on average but sometimes it can solve the problem with only 6 races.
Yeah this was great. I was having a hard time until I saw you group them in to a,b,c,d,e based off of the rank of their race. I was getting stuck on the three fastest horses being in the same race initially but the re-grouping did the trick. The visual really helps.
Feel you, i was stuck at a minimum of 11 races , because i wasnt regrouping and i thought id always have to let the top 3 of every race continue in case the 3 fastest horses happened to be in the same race at the start.
Outcomes are dependent on competition. This is a software developer question written in a bubble. And he didn't specify time , vs, outcome. Race six runs the winner of each group, but it takes a minimum of two races to remove all the second and third place finishers. Therefore his solution is wrong. It's not right.
@@sasquatchrosefarts What do you mean? After race 6 you know no horse behind the third place horse can win, 1 horse behind the second place horse gets a chance for third place, 2 horses behind the first place horse get a chance for second and third place, the winner of the winners definitely is first place, leaving 5 horses to be checked so we finally know the second and third place. When you identify a horse is slower than a horse that turns out to be slower than a slow horse then you also learn something about the first horse even though you didn't let it race again. Horses can be identified to be slower after a later race. If I misunderstood can you explain why you consider the solution to be wrong?
@@esco8778 Well you order the groups based on the place their "winner horse" made at the "winners race". So you have the 5 races at the start, after that the 5 winner horses will race each other. After that you order the groups by the finishing order of the groups fastest horse in the "winners race". So if the winner horse of group C also wins the "winners race" group C will be the "fastest group".
I realized pretty quickly that 6 races isn't enough, at which point I decided it's to complex and might require like 20 races or something. Glad to see such an elegant solution, thank you!
@@galacticlava1475 2nd place horse in 6th race might be slower than second place from the race the first place horse raced in. for all we know, that specific race might have consisted of the 5 fastest horses in the herd. thats why we take the 2nd and 3rd horse from that group, because even if 2nd place horse in race 6 is faster than 2nd place horse in race with the overall fastest horse, it may still be slower than 3rd place horse in that race. you consider the 2nd place horse in the race producing the 2nd fastest in the 6th race as u want to find the top 3 horses in speed, as 2nd place horse in 6th race might be faster than 2nd place horse in race that produced the fastest horse. Lastly, u include no3 from 6th race as all these extra horses included can still be slower than it, and if so, u still have ur fastest 3.
for people getting 6 races, we’re trying to find a method which guarantees the top 3 horses will be found. after the first 5 races, there are 15 horses which could still potentially be top 3 overall, and after the 6th race, there are still 5 in contention, including some of those 15 who didn’t win their initial race.
I know I will never work at these kinds of places, but to see the thought processes in these puzzles is awesome. Training yourself to look at the same real world problem in different perspectives to solve real world engineering/ self reliance problems are invaluable. Great video
This was before logic and rational thought was deemed racist. Now states like NY are outlawing 'tests' like this in the pursuit of 'equity' and we're slowly starting to fall behind other countries like China.
And it is open to interpretation, so some will interpret it in a way so you can label the horses and get 7 races, others will not label them and get 11 races. I would think a good answer would also be that the instructions are not complete
If you are looking to hire a programmer that's definitely not the answer you're looking for. If this were a simulation it would take less resources to program this solution in than to program in a clock. Programmers have to always think abstractly to find the most practical solutions.
@@bro748 That's also a very good answer. Also, if I hired a programmer, the only reason I'd have them out racing horses without proper equipment, would be as a punishment. Or maybe as a reward, depending on the programmer.
@@bro748 If you are looking to hire a programmer, you want to get a solution that does not blow up in your face when you get a 26th horse and the algorithm is just not working anymore. So you should phrase this as a more general problem with N horses. And then it gets interesting whether you want to find a generalizable algorithm that performs well on both low and high numbers or something that switches in between. Adding a clock scales nicely O(n), which is the best you can get with this, so this is actually one of the best answers. :P
I was getting 9 as a first effort but then as soon as you said 7 I was able to figure out how to get 7… It’s truly wonderful how much knowing that something can be done can influence your ability to do that something
Just like our full potential as a living being. Very few people know this and it then makes it impossible to achieve it until you are taught it by someone who has achieved their full potential. Most believe it is impossible only because they don't know how.
I came up with 8 races and proved it using pennies as horses. I didn't consider the 7th race could determine both the 2nd and 3rd fastest horses by eliminating the entire field of horses that only had 1 winner (race 1 -5). Thanks for posting.
I got 8 as well, but then when I saw the actual solution was 7 I immediately noticed we repeat the 7th and 8th race with the bottom 2 horses that have absolutely no hope of ever winning a top spot, and so worked out the best solution from there. So I worked out how to do it in 7 after seeing the solution was 7, but before seeing how to do it.
I also got 8. It is easier to find a solution that is not optimal, but that is fine in computer science. After you found a solution that works, you should seek to find a better solution, if necessary. 👍
I got 6, but I was wrong. I assumed the first 3 winners of the 6th race were the 3 fastest, without considering that they hadn't raced yet against those of higher level
I think it also depends on who is keeping track and actually watching the races. Alice or Bob would be able to figure it out. Charlie is either selling popcorn or shoveling the stalls.
the answer he gave is not correckt! The problem is that you dont have a time/ watch nor a distance! If you let 5 groups run, and you take the 1st. of each group, you can not be sure if these horses are one of the fastest 3. 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! . you have to have a constant to really get the 3 fastest! My logic: So you let the first 5 race, then you let the first second and third place on the track and get 2 new ones in, every race the 4,5 will be replaced. with this method you have always a constant for first, second and third place without needing a watch ! each race, 11 in total , will naturaly eliminate 4 and 5 place ! imagine this: lets say the first group are the 5 slowest of all, so the slowest up to the 5th slowest of all. in the second race the 4th and 5th place gets replaced with (in this simplyfiyed case)faster ones, and maybe one is the fastest of all and the other one the 2nd fastest of all. they will be 1st and 2nd place of the 2nd race and they will stay on this position. the 3th will be found after all other races are finished. You can switch the start situation, that the first 5er group have two of the fastest of all in it, so the first and second place will be set after the first race, and again the other races and just to find the real 3th place.---- i think its 11 races ! 😃
@@crashoverwrite5196 > 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! No. If you look carefully at the solution, the groups "a, b, c, d, e" are named *after* the 6th race. the winner of group a is the 1st place of the winners, the winner of group b is the 2nd place of the winners, so by definition a_1 > b_1 > c_1 > d_1 > e_1 - and then, you have a tree from the winner, you only want the top 3 so you can eliminate any that are 4th or more from the winner, and you are left with exactly 5 horses to race and find the 2nd, 3rd overall
@@sodiboo You dont know how fast they are! so my asumtion is valid. You need a fix point for the 1st,2nd and 3rd place. my comment was based on the crux, not the solution he gave.
@Dpg Dpg You didn't calculate it, you looked it up. Sorry you don't pass In order to calculate it, you must take drag a line from the edge of the earth to the edge of the sun
Because every horse in group D or E is by definition slower than top C which is AT BEST the third fastest(top B and top A beat it in a race). So at best every horse in D and E can be fourth fastest and can therefore be eliminated.
So if following this example the times for slowest to fastest in each group are as follows: A: 10, 9, 8, 7, 6 B: 14, 13, 12, 11, 10 C: 15, 14, 13, 12, 11 D: 16, 15, 14, 13, 12 E: 17, 16, 15, 14, 13 How is it valid to eliminate a3-a5 as being slower than b1?
You're not eliminating A3, you're eliminating A4-A5, B3-B5, C2-C5, all of D and all of E. Which will always be valid. You're not eliminating them for being slower than B1, you're eliminating them for being slower than AT LEAST 3 other horses. The final race is A3, A2, B1, B2, and C1 since those are the only horses left that aren't confirmed to be slower than at least 3 others.
So something we talked about in economics the other day is how if you take too much time to solve a problem in the most efficient way it can be more costly than just doing the inefficient way that instantly comes to mind. The answer I came up with was 11. I know it’s not even close to 7 but if I was able to have a system ready in 10 seconds that works I’m still proud of that answer Edit: very happy with the conclusion of the video though. Super cool thought process!!
But then again, if you spent a bit longer thinking more efficient solution you would save 4 races. That's 20 races you would have saved those mechanical horses from doing. If you do this more than once the maintenance costs are going to pass your thinking time.
well, this makes sense to me, but i think that if u create the best solutions u will be faster to create the best solutions next time and everytime, and maybe just at the start is harder, maybe
I think he is wrong, he would not be hired by Google. (About the answer in the video) I think he assumes that all horses finish at equal time intervals. The fastest horse, without any timing available, doesnt say anything aboit the slowest horse. The horse that finished 2nd to the fastest of all horses (the fastest group) could still be slower than the horse that finished 2nd to the horse that finished #5 in the 'race of winners' So without also determining which are the slowest horses this is just assumption. I'd say one need at least 8 races therefore. 11 is making sure anyway. Cross reference and you can make the whole top25.
The mathematically optimal answer shown in the video is satisfying to discover! The use of this method seems to be dependent on the specific numbers of total horses and horses per race presented in the problem, though... While trying to solve the problem, I came up with an algorithm which has the advantage of generalizing smoothly to any variation of the problem with M horses in the pool, N horses allowed per race and K spots at the top of the field, where K ≤ (N+1)/2. Here it is: Start: Have a group of untested horses, and a "leaderboard" with K spots. All M horses start in the untested group. Place N untested horses in the lineup for the next race. Run [Race Type A]. [Race Type A] Race the horses in the group; place the top K on the leaderboard, in order, and throw out the (N - K) horses at the bottom. Now add the horse in Kth place on the leaderboard, and (N - 1) untested horses, to the racing group. Run [Race Type B]. [Race Type B] Run the race with the current group. The next step depends on the outcome of the race: If the horse currently in Kth place on the leaderboard wins the race, eliminate all the other horses in the race and set up the next race with the Kth horse and (N - 1) new horses. No change to the leaderboard. Run [Race Type B]. If the Kth horse comes in 2nd or worse, eliminate the Kth horse and all horses in the race who were slower. If K or more horses beat the Kth horse, add the top K finishers to the next race; otherwise, add all horses who placed above the Kth horse. Add the other K-1 horses on the leaderboard to the race. Fill the remaining spots in the race, if any, with more untested horses. Run [Race Type A]. When no more untested horses remain, the leaderboard contains the K fastest horses. I ran a Monte Carlo simulation of this algorithm with 10,000 trials, and for the values given in the problem (M=25, N=5, K=3), the expected number of races is just under 8. Not bad!
This is interesting! What does a simulation find in the situation (M=25, N=5, K=2)? By the way, the approach of the video's method isn't necessarily the optimal one though. For example, in the case of (M=4, N=2, K=2), the video's approach would suggest that 4 races is optimal. However, it's relatively easy to find a method that takes 3 races in 1/3 of all possible scenarios, and 4 races in the other 2/3 of scenarios, thereby resulting in the optimal method that requires 11/3 = 3.6666... races on average; which is more efficient than 4 races. And maybe 7 races is optimal for the case finding the Top 3 out of 25 horses, but the video failed to give a solid proof of it (the "proof of minimality" in the video is flawed).
Locking in my answer: After racing 5 sets of 5, you can eliminate the 2 slowest of each set of 5. Then if you race the tops from each set, you can eliminate everything from the worst 2 sets of 5. You now know the fastest. The remaining 2 horses from the set whose winner ranked 3rd can be eliminated and the 3rd place of the set whose winner ranked 2nd can be eliminated, leaving the battle for 2nd and 3rd between the 2nd and 3rd from the set whose winner was the best, the 2nd place horse of the 2nd place among winners, and the 3rd place among winners. Race those 5 horses, find the top 2 and they are your 2nd and 3rd. 7 races total. edit: nailed it :)
I'm the interviewer, I'm now wishing I'd never asked this question after hearing 27 variations of how to solve it. It's late Friday and I want to finish work. . . . . . .First one to tell me, 'Sell 22 of them, keep the cash!' Gets the job! I don't care, I'm retiring next week.
What has happened about retiring next week? Are you so busy making the papers ready that you forgot you had announced your retirement publicly on TH-cam?
This was actually a pretty good case of problem where you can start from easier examples to get the solution. I took «fastest 2 of 4 with 2 racing at a time» and «fastest 3 of 9 with 3 racing at a time» which brought me to idea of elimination in no time.
Running through this pretty quickly, I got 11 races. 5 horizontal, 5 vertical, then a final race to determine the order. Love the logic in this. Shortest route to the best answer.
@@ZimCrusher Sorry, but what are you talking about, "when you are allowed to reshuffle based on performance" ? And first you said "Shortest route to the best answer", and now it's "I was over complicating the puzzle" ? And why aren't you simply answering my question: which horses would you pick for the final (= 11th) race?
@@yurenchu When I ran my solution, I would always end up with overlap. Meaning, There would be horses that won both vertically, and horizontally, in the final count, so there would only be 6 horses remaining. I would run the horses that won both races, and then just fill in the race with 1-2 of the single entries. This always gave me the top 3, but I only ran it 100 times. Looking, now at my code, it should have given me a few end results where one of the top 3 was left out. So... my solution fails as a perfect solution, not even counting that I needed 11 races, to their 7.
@@ZimCrusher Thank you for your reply and your explanations. Ah, now I get it. Previously I assumed that when you said "vertical", it meant that after the first five races, the first place finishers raced against eachother in race 6, the 2nd place horses raced against eachother in race 7, the 3rd place finishers raced against each other in race 8, and so on. Because that was an approach that was suggested by another commenter that I vaguely still remember. I didn't understand that you meant "vertical" as in how these 25 horses were arranged in a 5-by-5 matrix from the start, before any races were run. That makes the analysis interesting but much more complicated though. And yes, it appears that there would be scenarios where one of the Top3 would be left out (in 11 races), since after the first ten races, it's possible (for example) that the #3 fastest horse overall has lost both of its races (and hence dodges "detection"/won't be selected for the 11th race), while five other horses have won both of their races. Anyway, thanks for your reply.
I came up with the optimal solution in a few minutes with pen and paper, but I guess it's easy to get stuck if you miss some piece of information. I thought it was easier to think backwards: first you definitely need 5 races to race each horse once. The two slowest horses from each race is definitely not part of the top 3. You are now left with five groups with three horses (15 in total). You don't want to race them all against each other, so you can rank the groups relatively to each other by racing the slowest or the fastest in each group. Since we're looking for the fastest ones, intuitively it makes more sense to rank by the fastest, so we race the fastest horse in each group in the semifinal. All the horses in the two groups represented by the last two horses in this race will all be slower than the fastest three horses in this race. We're left with three groups, with three horses in each (9 in total). Some observations at this point: - The fastest horse is identified, as the fastest horse from the semifinal - There are three ways that the three fastest horses can be arranged into the three fastest groups: the top three from the fastest group, the fastest horse plus the two fastest horses in the second fastest group, or finally the fastest horse in each of the three fastest groups. This gives us 6 candidates for the three fastest horses. Realizing that the fastest one is already identified leaves us with five horses to race the final. The two fastest horses in the final are the second and third fastest horses. Alternative solutions: - 1 race: Race 3 randomly selected horses. The other ones have never competed so their time is undefined. - 0 races: Shoot 22 horses.
I got the same result with the same reasoning, except note that when you say "there are three ways..." there are actually four; you could also have the fastest horse, the second fastest horse from that same group, and the fastest horse from the second fastest group. That doesn't change anything about the rest of your explanation though :)
I made it seven, but it was a bit of a guess. I got as far as racing five groups of five and then racing the winners, giving six races. After that I figured one more race should do it, but more by intuition than reasoning. The step that eluded me was that any horse beaten by three others could be eliminated, although that seems obvious, now you mention it. I think I would have got there eventually, but it's easy to say that and my working would most likely have involved some extra unnecessary steps. Thanks for the clarification 🙂
This is something I learned in grad school. For any top-N problem, the tournament algorithm produces the minimal time solution, same O-notation complexity, but lower constant factor due to decreased pairwise comparisons.
The general extension of this algo would have been an excellent interview question with a runtime and proof of completeness. It felt good to know I got this one right when I did it.
Google doesn't actually use these sorts of logic puzzles in interviews. At least they haven't for the last 20 years or so. They ask algorithmic/coding questions, system design questions, questions that check technical knowledge and the like. There are lots of videos posted by Google about how to prep for a Google interview. But tl;dr, re-read Introduction to Algorithms (AKA the mobile book).
Ehh it isn't far from common questions I was giving people 5 years ago in google interviews. They moved away from the how many rats in new york city type of question pretty quickly. But logic questions are common. By the time I was interviewing people we were generally trying to make sure all the logic questions included a degree of psudo code as part of the answer. But in spirit this problem is pretty close to what we would be asking.
Something i think could be explained as i didnt initially think of it and other ppl dont seem to have noticed is the fastest horse of a given race could still be slower than the slowest horse in another race. Just depends on luck of the initial groups
I was thinking about this too, but with this method, it won't matter. Even if the horses are arranged strictly by performance (the slowest in group A is faster than the fastest in group B), it will just mean that the winners of race 7 (2nd and 3rd fastest overall) will all come from group A
There is another problem in every race the horses are randomly asigned and you don't have the time so by that definition in one of the groups you can still have the 1 fastes hourse and 2nd fastes from all 25 hourses, but by this method of elimination you have already decided that the secound fastes hourse is no longer competing and the 1st fastes hourse is compeeting to the once left from other groups.
@Moh Taw, - "What if the 5 horses in group "a" were actually faster than all other horses ... How you will solve it without a watch" That's exactly why horses a2 and a3 also participate in the seventh race (along with b1, b2 and c1), which they will win in your scenario.
ideal horses too, so individually they have no volume but occupy a finite space together. They also do not attract each other so little ponies won't be made
@@backwashjoe7864 I’d argue that being frictionless and in a vacuum were redundant, but… Instead I’m going to add that they should also be made up of non-baryonic matter so as not to be affected by virtual particles. Frictionless non-baryonic spherical horses in a vacuum.
I just want to say, your question is exponentially better than the common interview question. Me sitting here with tired horses, one fell in a race....
@@fmobus you do understand what an exponential equation looks like right? Calling something exponentially better is in comparison to calling it linearly better, where something exponentially better reaches its limit faster than something that reaches its limit linearly. So “exponentially better” means “a lot better” and “exponentially more” means “a lot more”…
@@jordantyler148 actually Im not sure, imight have been right, but not the way i thought. You say it isnt a solution unless it works in all cases, but what if i had a method that gives the answer in 6 rounds if and only if all top 3 horses are in the first group, and gives it in 7 rounds if not? Im not sure if I have such a method, but if I did it would be a better answer than the video, would it not?
@@jasonbernard5468 It would be interesting if you had a method that sometimes worked in 6 rounds, but occasionally needed an additional round, but only if you knew if it was done after 6 rounds, not if you do the 6 rounds and you dont know if its right.
@@jordantyler148 There is a method that works for all cases and in best case is only 6 races, but worst case 11. It does not involve doing 5 races with all horses like this. You do an initial race which gives you an initial #1, #2, #3. You take you 3rd place and race it against 4 new horses. If any are faster than current #3 then you race the fastest 3 of those against your current #1 and #2, giving you a new set of finishers. And continue with whatever the current #3 is. Best case, they are in order and you do 1 initial race plus 5 additionals where none are faster that that first #3, so 6 total races. Worst case they are in reverse order. and you will have to re-race after each of the 5 races, so 11 max. The question is to find the minimum, not the most optimal solution. So this would be a "better" answer.
The fact that you specified that each time had to be different is what gave it away for me. But, that also made me think, without that detail the original puzzle would be almost impossible if you take into account that horses could finish at the same time and drawing for places.
I think the key thing to think about is that A1 is automatically in so you are now looking for the fastest combination to fill 2 spots. So if there are only 2 spots then you know that anyone in group D or E is out because there just aren't enough slots for them. Everyone in D group is slower than D1 and D1 is slower than C1. So the LONGEST possible path is A1 to C1 (because B1 will always be faster than C1. This is also why C2 is out of contention, which threw me for a second). The shortest possible path is A1 to A3. A1 is automatically in. You just need to test the viable permutations of the fastest 3 horses. So their are 4 possible outcomes that include only the 3 fastest horses. They are: A1, A2, A3 A1, A2, B1 A1, B1, C1 A1, B1, B2 So if you ignore the A1s since you automatically know they are automatically the fastest of the fast, you get the horses you need to test against each other being A2, A3, B1, C1, and B2. That's 5 horses which works out perfectly for a 7th race!
You have no way of knowing if any 2nd place is slower then anyone but your 1st and 1st places above your group. For all we know E2 and even E5 can be faster then A2. From racing initial groups and winners you cant derive rest of field. You do not know times so there can be massive diference between 1st and 2nd places. Dont forget that initial groups are random. Edit: nwm, it clicked for me after i read @frorkbrunk148 comment.
My solution was to grab 5 horses, race them, put the slowest two aside and grab two more to race off against the fastest 3 so far identified, after this race, the losers will be put aside and two new horses will face off against the fastest three from the second race, etc. Not particularly quick, but since the horses won't get tired, you will eventually end up with the three fastest horses
@@fayt9121 that doesn’t work. Lets say the second fastest horse was in the same heat as the fastest horse of all 25 horses. Then the second fastest horse would never be included in your final (6th) run.
@@Macarthurmaintenance this is true. so you are saying you have to race a total of 8 times since you want the 3 fastest horses right? you do your first six to find which one is the fastest and then you race second and third place against the winners from groups 2-5. I get that. And with this hypothetical, its possible that the horses don't get tired either. Ill be honest I cant put my finger on it but something's bothering me about this.
There are ways to learn this in 0 races. Consider disassembling one horse, reverse engineering its software to find where the horses movement rate is located, then hack the other 24 horses and learn their rates without the horse moving. The question is "The three fastest horses" not "Rank the horses by the fastest" Another way is to destroy all but three of the horses, and then you automatically know the three fastest horses.
It's a programming problem, ie why Google would ask it to a potential employee. It doesn't really matter what horse is the 1st, 2nd, and 3rd fastest, they're trying to get you to come up with a problem-solving technique to identify what those horses are. Programming is all about developing these techniques, the actual numbers/results don't matter so long as the techniques are correct.
@@digiquo8143 Agreed. There are all kinds of videos on you tube (including several other of the 25 horses problem) that pose intriguing puzzles that challenge your brain to think, find possible solutions, look at possibilities, and come up with sound techniques that will work in any case. Someone else here mentioned six races, and when I worked through his logic, I found out that he was in fact correct, but it only worked in 2 possible cases, both of which were statistically insignificant. The correct technique, as shown in this video, will hold up rigorously for all cases.
I was started to write a long comment throughly explaining why I disagreed with your answer. I read through the comments before responding to see if others came up with the same conclusion. Upon reading those comments, others had realized what I had, and explained how they were confused and why your answer made sense. I see where I was wrong, after reading the comments. If the 4th, and 5th place horse from the the 6th race were the fastest in their group, that entire group is eliminated. Even the 3rd place horse would be the very minimum possibility. Excellent mind puzzle, made me think thank you.
I was starting to do the same - only when I scanned through comments I was only surprised that everyone except me was in agreement. If the horses are divided randomly into even groups of 5 - how do we know that all of the top 3 are not in the same group and therefore 2nd and 3rd place are not automically incorrectly eliminated?
No it actually is not. On placing yes, but with actual times it can be very different. For instance A1 can run 1min but A2 needed 5min and the whole group E can still lie between them
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now but they got eliminated so can't race horse 3rd place so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
@@DreadX10 race horses in sets of 5 and kill the ones not 1st place, 5 races. Race remaining horses and kill 5th and 4th place. 6 races. You are now certain that the 3 horses you picked are the fastest of the original 25.
@@ozzygilliam9194 ...but two or three of the fastest horses might (by chance) be in your group of 5, so then you would have shot one or two of the fastest horses. you could race them in groups of 5 and the two slowest are retired (see Blade Runner).
Interesting puzzle. I didn’t initially find the explanation very helpful, except it made me question my initial answer until I could work out the solution. Good stuff.
I get it, but jumped to the initial conclusion of 6 races. I’ll say that I knew I was wrong and that I was missing something. Good lesson here, I’m glad I watched.
I was about to, but then I thought "what if all 3 fastest horses is in the same group? This can't be the solution." I couldn't figure out the right answer though.
Sorry, Mäx-Tick, but someone with a background in math posted a solid proof in this comment section 8 months ago, showing that it's impossible to design a method that is guaranteed to identify the three fastest horses every time in just 6 races.
I was wondering how you could find the 2nd and 3rd fastest overall. The other method I came up with was more of a slider and would require 11 races, which works but isn't minimal. (Line up the horses, race the first 5, keep the top 3, add the next two horses, race and repeat)
I would race 5 groups of 5 and aswell remove to two slowest in each. Leaves 15, repeat, leaves 9, then 5 and of those it's the fastest three. 11 races (5 x 5horses, 3x5, 2x 5, and last race with 5)
@@aramisortsbottcher8201 Wrote out a very similar thing about a day after you did. I just continued to take the top 3, even when it left we with 9 instead of 10. When I got to 6, I ran one race with 5 and left one behind. Then ran it again with the last horse eliminated and the spare 6th plugged in. For a small touch of extra certainty.
@@robertdavis5693 I first had this idea too, but when the point with nine horses was arrived, I raced the first five and after that the next four, but filled the fifth slot with one of the previous race. That way I could sort out two of five instead of one of four horses. This left me with 5 instead of 6 horses, so they all fit into one race :D
I was getting 9 races: - 5 races to get the winners. Each race produces a 1st, 2nd and 3rd place - 3 races to find the fastest 1st place, 2nd place and 3rd place of the groups. This race produces the 3 fastest 1st places, 2nd places and 3rd places - 1 final race with the 3 fastest 1st places, the fastest 2nd place and the fastest 3rd place It was great to see it was doable in 7 though. Great puzzle!
This is damn good, man! Until I saw the visual elimination and the surprise at the end (that we don't need to race again the fastest horse) I couldn't wrap my head around it. Thank so much!!!
I had come up with 9 initially, but knew there had to be a smoother way to do it. Putting my thoughts into your nomenclature, I obviously started with 5 races. Then, I knew the bottom two from each race couldn't possibly be in the top three fastest, so they were eliminated. I'm now left with fifteen horses, A1-A3 to E1-E3. My thought was to take A1-A3 against B1 and B2. Take the three fastest from that heat, and run them against C1 and C2, and so on. Assuming you get lucky enough to not have to re-trial with any of the third finishers from B through E, you could get all the heats done and find the three fastest horses in 9 races. Obviously, the issue would arise if both of the two from the new group beat all three from the previous heat, but that would only end up adding a maximum of one additional heat, to a total of 10 races. I dismissed the idea of running the top finishers against each other too quickly, as I figured that only finds you the absolute fastest, and you've just spent a race only eliminating one option. I wish I had sat on that longer; I may have realized the implication of how many more horses you could eliminate by that one race. Great little thought puzzle, and I'll learn to not dismiss ideas so quickly next time.
Vsauce! Michael here. What you experienced is what we call "Jamais Vu". It's what you experience when a word has been spoken so many times that it loses its meaning. Thanks for watching, this has been Michael... or am I?
The smartest person seems to be the person who comes up with the question with the answer in mind. Honestly takes a lot of brain power to come up with a problem and solution a lot of people cant solve
I had 8 races with the 2nd place finishers do the 6th race, then eliminated half the field, then did 2 more rounds to be sure there were no stragglers in 3rd place. Elegant solution!
@@davidhawley1132 ok thanks David. I’ve noted your assumptions. I’ll speak to the client in relation to your concerns of legacy constraints and find out if these are going to be problematic... I have liased with them and it turns out that we live in 2021 and we’re dealing with a startup. It’s also apparent that there are already timing tools available on the market, so I’ve conducted build vs buy analysis and it makes sense to procure the stop watch instead. $3 from Amazon. Since finding the fastest horse is going to be repetitive it also means we can make huge time savings in efficiency across the product life cycle and there is less risk involving the horses. So I’m grateful for your input as this led to a cost saving of tens of thousands. I’m giving you a pay rise and I’ll write a case study based on your input for lessons learned in the next knowledge sharing workshop so we can all benefit from your unrivalled wisdom. Lol obviously this was not a serious solution dude.
@@davidhawley1132 We have "stopwatches" that work just fine in distributed simulations. It's a very difficult problem with an embarrassingly simple solution. (But, I'm also talking software - getting circuits in time without a common clock is something I'm not going to mess with, unless performance is not a concern.) (And who wants to work on something where performance is not a concern?) :D
I got 8 because I didn’t think to rearrange the groups based on the results of the 6th race. I was adding an additional step where all the 2nd place horses from each group raced but it was basically an inefficient way to get the same result that you’d get in the 7th race in this solution.
Had the exact same thought process, but a total eureka as soon as the video said "we split them into groups" and I went "OH WAIT WAIT WAIT IS SEE IT no point in racing the nr 4 and 5 horses from the winner race, that frees up 2 more slots!"
@@codrincx same and i got stuck on how to fit a3 in there cos what if all 3 fastest horses were in the same race, you dont need to race the fastest again freeing up another slot *d'oh* 🤦♂🤦♂🤦♂
@@onepun9583 If I'm understanding your comment right, then: The d and e group cannot imaginably matter, since after the first races, we know for sure that a1 > b1 > c1. Therefore, any horse from group e will be slower than *both* b1 and c1. The only horses that could be faster than b1 come from group a (as all horses in group c, d and e are all slower than b1), and then the only horses that could be faster than c1 come from groups a and b. Notice that in both scenarios you've written, b1 and c1 are the fastest, therefore the only ones actually relevant. If a2 or a3 (could also be a4 or a5, but we only care about top 3) isn't faster than b1, then b1 *is* the 2nd fastest horse. Similarly if b2 isn't faster than c1, then c1 *is* the 3rd fastest horse.
I had thought 6, but since you can theoretically get 3 horses faster than the 3rd fastest from the first race in each subsequent race, a minimum 7th race is required to resolve the final rankings (and possibly several more). My original bid was 11 - 5x5, and then 5x3 gives the fastest 9 horses. The 3rd fastest from the first of these races signposts the contenders from the remaining 4, which can be re-raced with the fastest two from the previous race in the final race.
They said minimum, meaning best scenario. So minimum is in fact 6. Run 5, then use 3rd place to run against the other 20. 3rd place beats all therefor you had your fastest 3 in only 6 turns
@@SharamanONorgannon you are assuming that the 3rd fastest from the first race is the 3rd fastest *overall.* What if horses #17 & #19 are faster? Sure - one of these is faster than the other, but you can't know whether both are faster than the 2nd fastest from the first race without a re-race. So now you have the 4 fastest horses, and don't know which of these are the 3 fastest - in fact, you don't even know which *single* horse is the fastest.
@@testname5042 They said best case. So you test the 3rd best from the first set against all the rest. In best case scenario the 3rd fastest from the first race IS the 3rd fastest overall therefor in 6 turns you can figure it out.
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now which is the eliminated ones and couldn't race to know for sure. so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
It’s honestly amazing how much a visual image can help someone figure out the solution. I ended up coming to the right answer just by visualizing it and thinking of the steps I need to take. A pen and paper also definitely helps 😅
I knew it was at least 6 to find the fastest, and I was sure that there was a way to do a seventh where you get the 2nd and 3rd, so the right answer was _probably_ 7. I didn't reason out the exact way to _do_ the 7th race, but I didn't need to bc I knew it was possible. I don't know how some people got 11 or 12
@@westofley 11 comes from racing 5 horses, then removing the 2 slowest and inserting 2 others until you have only the last 5 horses in which case the top 3 are the fastest 3 overall. You need to drop 22 horses in total, 2 horses per race means 11 races using this strategy.
@Wesley Pardo I still think it's 6 races total, 5 races to get top 5 from lot of 25 and from that lot of 5 you'll get 1st, 2nd and 3rd as it's mentioned in question that you'll get " printout with the order the horses finished" so that'll be the fastest three in the order provided in the printout.
@@vishulangeh8348 you don't know relative times so it's possible the horses that came in second and third for the first race are faster than all of the horses in other races. Assuming the second and third horses in the 6th race are faster than those horses from the first race is unjustified
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now but they got eliminated so can't race horse 3rd place so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
I’m rethinking this and hadn’t realized that the 2nd and 3rd place horse would be from other groups. I take back my comment about there being a logic flaw. Mea Culpa!
I couldn't figure it out, but it's very interesting. I was a bit confused as to why the last race has to include only from groups a,b and c, since groups f and e might have been faster, but then you said you named those groups after you placed them in order of their respective winners from fastest to slowest and it now makes perfect sense. It's a bitter sweet feeling realizing this elegant solution but at the same time failing to figure it out on your own.
@@joelpwwsame.. I was like from the last race just pick 1st 🥇 2nd 🥈 and 3rd 🥉 but then ℹ realised there’s no way to tell if the 2nd horse from the last race was actually faster than the 2nd from the first race. So it’s prolly 7races.
There is a way to know the 3 fastests in 6 races IF you are very lucky. But that falls into the minimum definition, so it would be the best answer that I can think of now. That method implies selecting the 3 fastest horses from the first race, separete the first two and run the third to compare with other 4 horses. If that horse wins all the next 5 races, ypu discard 4 horses each race. And in 6 races you ensure you have the 3 fastest IF you were lucky enough to include them in the first race.
Great find! Your algorithm works and can identify the 3 fastest horses in 6 rounds (if you’re lucky). It would be worse most of the time, depending on how you choose to race the horses that win over the 3rd place horse.
A solution similar to this occurred to me as well. It would eliminate 2 horses in the first race, then 2-4 in races 2-6. The best case scenario is it would give you 3 remaining horses, worst case you’d have 13. It’s possible you could optimize further, but I doubt you’d get an average significantly below 7, and probably somewhat above.
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now which is the eliminated ones and couldn't race to know for sure. so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
I get a paper and label the horses so and I based my time on the fastest one in each group so then I can tell which ones are the fastest Ones ( I will race the fastest of each group to see which one is the absolute fastest and based the speed on that one
My best answer would be run a horse race gambling game while doing the laziest solution done everyday making sure to keep horses always healthy, do it for 6 months to a year, you get money and you get the best horses trained after months of running 🥳. Since the fastest horse now wont necessarily be the consistently fastest horse, you need reliable statistics!
That's actually the correct answer, because it's said you don't have a watch, so you could never compare the times of each group's fastest horses, 2nd, 3rd, etc (one race at a time, remember?) The 2nd place from group A may be faster than group B's fastest horse. The guy who made this video may be good at math, but he surely lacks text interpretation...
I got the setup exactly the same up until the 6th round, but at the seventh round I couldn't quite get the final 2 horses. I thought c2 could be faster than a2 and b2 and got confused how I'd identify the 2nd and 3rd fastest horses with such complexity. What I missed is that c2 could infact be faster than a2 and b2, but it's irrelevant as in that case there is still a1, b1 and c1 faster. Looking at it from the other side and eliminating all the horses that can not possibly qualify for top 3 is by far the easiest and smartest solution. I didn't come up with that.
Exactly, also this implies how subjective is categorizing letters a to e in the same group as 2 to 5 since there is no timer, there's no way to know if A2 is actually faster than E1 because E1 could've for example finished in 5 seconds, A1 7, but that doesn't mean A2 couldn't have finished in 4.9 making it actually slower than E1
I still didn’t get it. C2 could in fact be faster than a1,a2, b1, b2. So we are missing that comparison. But you said that is irrelevant so just want to understand what I’m missing.
@@bhupendrasatpathy C2 can never be in the top 3 because it is already slower than at least 3 horses: A1, B1, and C1. It is slower than C1 because it lost the race with all the Cs. It’s slower than A1 and B1 because A1 and B1 are faster than C1 since they beat it in the race of the fastest among groups.
But all of B2 3 4 5 just means they slower than B1. All pf A2 3 4 5 just slower than A1. Theres no line where B2 3 4 5 faster than A2 3 4 5 because groups are ranked by heats. Say A1 is 10sec. B1 is 9sec. A2 3 4 5 could all be 4sec. B2 3 4 5 could all be 8sec.
Fun question! I initially got 8, using the basic outline for the solution but was just racing the 2nd place race from the one with the fastest horse against the other 4 again for 7, and then used my 8th to run the next fastest from the group with the second fastest horse against the remaining 4. Was able to get the solution method after seeing the answer was 7, but not sure if I would’ve seen the optimization on my own, at least not without a pencil and paper
@@writer_gupta_ji*(edit this method is flawed as pointed out by others below me)* I solved it in less then 2 minutes, tho I solved for 6-7 (ill explain that later) using a different method which is race 5 horses then race first place against 4 new repeat 5 times keeping track of the second place horses at the end of the sixth race if the fastest horse of race 5 isn't first or second then the top 3 are the 3 fastest else race 2nd place horse of race 5 against 3rd place of race 6 and first place of race 7 is 3rd fastest. This is a better solution because there is an 84.43% chance u will only need 6 races. *>>> AGAIN THIS METHOD IS FLAWED SO PLZ STOP COMMENTING THAT IM WRONG, I AM WELL AWARE.
@@nothingnothing1799 Maybe I am missing something, but how does your method work? Imagine if your very first race had all three fastest horses in it, and you basically eliminate the 2nd and 3rd fastest ones at the very beginning, and never return to them in your procedure above, how do you get to the top three?
personally I thought it was 6, 25/5 for the 5 initial races and then 1 with the winners, surely first, second and third place meet all those requirements, 3 fastest horses, I hadn't thought about the fact that 2nd place in group A could be faster than 3rd place Group C in race 6, interesting, something to think about
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now but they got eliminated so can't race horse 3rd place so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
First thought on this was 8. Race all groups (5 races), then race the winners of each (1 race) then race the winners again replacing the fastest overall with the runner up in the group repeating twice (2 races) Didn't think to remove the e and d groups like you showed and let them keep racing even though they could never be top 3
1:33 I was able to get a 10-race solution. Racing , and thereby sorting the 5 rows of horses, I obtain 5 columns, the last two of which can be discarded as they definitely don't have the 3 fastest horses. I sort the 3 columns, and I obtain a group of 6 horses, of which I know the 3 fastest exist. By racing two different groups of 5 of the 6 horses, you can figure out which are the fastest over all.
My first idea was taking the 2 slowest off each time as well. Ended up with 11 races however I appreciate it can be done in less. But upon further contemplation I figured if I'm at Google I'd just pick 3 random horses. The truth is what we say it is.
Same idea here. A way with less races may possibly exist, but designing and verifying its veracity likely takes longer than the few races that it might save us, so we better simply get those horses to run. One could ask the interviewer, "is the question here really about the best algorithm, or is it about figuring out which are the three fastest horses in the most efficient way?"
yes man. you got it with 11. The problem is that you dont have a time/ watch nor a distance! If you let 5 groups run, and you take the 1st. of each group, you can not be sure if these horses are one of the fastest 3. 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! . you have to have a constant to really get the 3 fastest! My logic: So you let the first 5 race, then you let the first second and third place on the track and get 2 new ones in, every race the 4,5 will be replaced. with this method you have always a constant for first, second and third place without needing a watch ! each race, 11 in total , will naturaly eliminate 4 and 5 place ! imagine this: lets say the first group are the 5 slowest of all, so the slowest up to the 5th slowest of all. in the second race the 4th and 5th place gets replaced with (in this simplyfiyed case)faster ones, and maybe one is the fastest of all and the other one the 2nd fastest of all. they will be 1st and 2nd place of the 2nd race and they will stay on this position. the 3th will be found after all other races are finished. You can switch the start situation, that the first 5er group have two of the fastest of all in it, so the first and second place will be set after the first race, and again the other races and just to find the real 3th place.---- i think its 11 races ! 😃
I started out saying 10, then realized I could eliminate the 4th and 5th place horses from the first 5 races. Just as I was patting myself on the back and saying the answer was 8 races, the rest of the video played. Guess I'm not as smart as I thought I was.
@@johns9652 6 races, because reality isn't so comfortable; you have the winners run, and the winner of winners is the fastest with 2nd & 3rd place marked behind it. If UFC, or other events operated like y'all are suggesting, then all competition sports should be eliminated, and all champions should return their trophies.
I used that approach initially. 25 horses to start, 5 races, two slowest eliminated each race, 15 horses left. 3 races, two slowest eliminated each race, 9 horses left. 2 races, but with nine horses, you'll have one group of five and one group of four, and you need to keep the fastest three from each group, so eliminate the two slowest from the group of five, but only one from the group of four. This creates somewhat of a dilemma, as you have already run 10 races and you still have 6 horses. Run a race of five, with the sixth sitting out. Knock out the two slowest from that group, leaving the three fastest and with the one that sat out, that's four remaining. That was 11 races so far The final race will show who is 1-2-3 out of the original 25. But that was 12 races.
I understood how you got the three fastest horses in seven races (in a few minutes after I finished watching the video). I drew the diagrams you drew, and I began eliminating horses.
Its not correckt! The problem is that you dont have a time/ watch nor a distance! If you let 5 groups run, and you take the 1st. of each group, you can not be sure if these horses are one of the fastest 3. 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! . you have to have a constant to really get the 3 fastest! My logic: So you let the first 5 race, then you let the first second and third place on the track and get 2 new ones in, every race the 4,5 will be replaced. with this method you have always a constant for first, second and third place without needing a watch ! each race, 11 in total , will naturaly eliminate 4 and 5 place ! imagine this: lets say the first group are the 5 slowest of all, so the slowest up to the 5th slowest of all. in the second race the 4th and 5th place gets replaced with (in this simplyfiyed case)faster ones, and maybe one is the fastest of all and the other one the 2nd fastest of all. they will be 1st and 2nd place of the 2nd race and they will stay on this position. the 3th will be found after all other races are finished. You can switch the start situation, that the first 5er group have two of the fastest of all in it, so the first and second place will be set after the first race, and again the other races and just to find the real 3th place.---- i think its 11 races ! 😃
@@crashoverwrite5196 Yeah. My first thought was to do what you described, but I abandoned that quickly because I knew it would require more races than necessary. I figured it out quickly enough. The answer is 7. Just pay attention to what is said in the video.
@@crashoverwrite5196 What about if you ran the first 6 races as described in the video but for the seventh, ran all 2nd place finishing horses from the first 5 races against one another and for the 8th (and final race) run the top two horses from both of the 6th and 7th races?
I'm not sure about all combinations of numbers of horses etc, but the method in the video works for ¼(k-1)²(k+2)² horses where you can race ½(k-1)(k+2) horses in each race.
I think it's more adequately written as (½(k-1)(k+2))² horses and ½(k-1)(k+2) horses per race. That makes it more obvious the former is the square of the latter.
+codebeard Is k the number of horses we're trying to find, or is it just a coincidence that k=3 for 25 horses? If k is the number of horse we're trying to find, the minimum number of races is ½(k-1)(k+2) + 2.
Mechanical horses make so much more sense, in the beginning I was thinking of actual horses where you'd have to consider how many races each individual horse ran to make it fair in comparison
Yeah this generally applies to a lot of tech interview questions: there might be a simplifying assumption that needs to be made, and it won't always tell you what that is. If horse performance is variable, the question doesn't really have an answer, or it has a complicated answer with probabilities. With the information that's given, always take the simplest version of the question you can-that's usually what's intended. You can explain: "Based on the wording of the question, I'll make a simplifying assumption here that each horse can be mapped to a single numerical speed value, and it doesn't change between races". That's the kind of thing an interviewer is looking for, it shows that you see how complicated it *could* get but you know you don't have enough information for that to be the intended question.
Yeah, in the real world there is no perfect solution, because the horses might perform better or worse on a given race for different reasons.. the dead slowest horse could be sick but normally be the best, some may have more stamina and thus do better in later races, etc..
Before reading comments or finishing the video: Five initial rounds with five of the twenty five horses each. 4th place and 5th place from each race is removed, leaving the 1st, 2nd, and 3rd place winners. At this point any of those three could be our top three so we have to include them for now. This leaves 15. Sixth round pits the 1st place horses from the first five rounds against each other. We can then remove 4th and 5th place, as they obviously can't measure up, but we can also remove the 2nd and 3rd place horses from their races since they obviously can't be faster than the top three. We can also remove the 2nd and 3rd place horses from the race the horse that got 3rd in the sixth round came from since they also can't out-speed the top three. Then we can remove the 3rd place horse from the race the 2nd place horse in round six came from since both the 1st place horse from round six and the two horses that out-sped it in its first round are faster than it, knocking it out of the top three. Finally, we can remove the 1st place horse from this equation. We know it's the fastest because it out-sped all other horses which in turn out-sped all of the others together. This narrows it down to five; 2nd place from round six, 3rd place from round six, the 2nd and 3rd place horses from the round the 1st place horse came from, and the 2nd place horse from the race the 2nd place horse in round six came from. The seventh round features these five horses, and the top two are 2nd place and 3rd place overall after the horse we've already singled out as being first place. So my answer is 7.
i came up with 7 as well. but in further thought i find myself with a different answer. what if horse a5 is faster than horse b1? there isnt a test race to prove that it isnt.
@@kajsorensen5652 the main point why a5 and a4 are eliminated is that even if they were faster than b1, rhey are slower than a1, a2 and a3 so theres no point in even pitting a5/4 in there
"Five initial rounds with five of the twenty five horses each. 4th place and 5th place from each race is removed" No, the 5th horse in one group can be faster than the 1st horse in another group.
@@muhammadshafieebinkhaidzir6371 thank you so much! I couldn’t understand why he eliminated a4, a5, b3, b4, b5 and c2-c5 but your simple and succinct answer made it so clear. Thank you again!
I'm genuinely curious what percentage of people still have watches. They seem kind of redundant now TBH. Edit - and by have I mean "actually wear and use". Buried in the couch or the back of a junk drawer isn't what I'm talking about.
Nice puzzle, my first instinct was 11, should have thought about it more to think about what the results of the first five races meant. I thought about racing the fastest, but glossed over that eliminating the slowest two also limited the other four that were in their original groups AND the slower horses in the other groups.
Yeah i also think its 11 by eliminate every horse on 4 and 5 spot. And i think about this just under a minute. But yeah if i had think long enough and do critical thinking i could arrive at the answer for 7
11 seems correct. The solution of this video does not seem correct. Without racing #2 of race 1 against #1 of race 2, how does one know that #2 of race 1 should be eliminated? What if all 3 fastest horses were in fact within race 1, but #2 and #3 of race 1 were inadvertently removed from subsequent comparisons against all other slower horses?
@@thangd7124 yeah 11 is also correct. The solution in this video is correct too. In step two, because we already found the fastest horse in the group of 25 (1st place of the group "a"), we know that the 3 fastest horses might be all three in group "a" (case 1). In group "b", we only consider 2nd place and 1st place horses, we remove the 3rd place horse in this group because we only need to find the 3 fastest horses (one is known in group "a"), now the 3 fastest horses might be "1st place group a, 1st place group b, 2nd place group b" (case 2). In group "c", we consider only the 1st place horse, the 3 fastest horses might be "1st place group a, 1st place group b, 1st place group c" (case 3). At 7:21, we have three cases to consider knowing that the fastest horse is 1st place group a horse. case 1: 1st place group a, 2nd place group a, 3rd place group a case 2: 1st place group a, 1st place group b, 2nd place group b case 3: 1st place group a, 1st place group b, 1st place group c The three fastest horses could be in one of the cases, but we don't know which case. What we know is the 1st place group a horse is the fastest. Therefore, we can leave out the 1st place group a horse and race the others to find the second and the third fastest horses. case 1: 2nd place group a, 3rd place group c case 2: 1st place group b, 2nd place group b case 3: 1st place group b, 1st place group c race 2nd place group a, 3rd place group c, 1st place group b, 2nd place group b, 1st place group c
My one issue with the 5x5 grid of slowest/fastest winners was I thought to my self "How do you get that after 5 races???" But then I realized that the 6th race will tell you who was the fastest and slowest of winners. Great stuff.
This part is key and I don't think it get's the attention needed in the explanation. 5 races is minimum to race each horse at least once, and the 6th race is key because not only do you get the winning horse, but you also get the ordering of the groups. This allows you to determine the horses for the last round no. 7. Without the info from race no.6 you have no way to compare the groups between themselves.
@@Productlivity_ZZ I don't get why you even need the groupings though. Wouldn't the top 5 winners already be the fastest of their groups So you only need to race the winners to get the fastest horses.
@@izzy123123123 If the three quickest horses happen to be placed in group a, the third horse of group a could be faster than the winner of any of the other groups
I got stumbled at "5 races give five " Fastest" Horses from each group, and the fastest among them is the first overall. But how exactly do I proceed with the 2nd and 3rd? " And I am happy about your explanation
Damn I feel like I got pretty close. I immediately had 2 ideas. The first method was to just keep the top 3 and add another 2 new horses until complete, which is 11 races. The other idea was to use a bracket and I figured out to get the fastest overall requires 6 races, but for second and third place I just did the same thing and compared the second fastest from the winner's group to the second fastest from the initial groups which gave me 8. Intuitively I could feel this was wrong though, and if I had actually wrote any of this down instead of trying to solve in my head I probably would have done a lot better, but even still I'm not sure I would have seen that last step. What I've learned here is knowing when and how to use grids can be extremely useful, and that I should note things down.
How did you determine the top 3 fastest groups? In my opinion, it would require a total of 8 races. The first 5 races would be used to divide all 25 horses into groups, then an additional race would be conducted with the fastest horse from each group. Next, another race would involve the second-place horses from each group, and finally, a race would be held with the third-place horses from each group.
its by the order the 6th race finishes in. The horses that finish 4th and 5th in this race obviously are not in the quickest 3, and the other 4 horses in each of thier groups obviously are not either, so thats 10 nags eliminated. That leaves 9 horses (as you also eliminate the slowest 2 from every group). The horse that finishes 3rd is slower than the horses that finish 2nd and 1st in this race, and faster than all the rest of the horses its its group, so them 2 are eliminated. The horse that finishes 2nd is slower than the winner, so the horse that finished 3rd in THAT horses group is eliminated since we know there are at least 3 faster horses. That leaves 6 horses, so you race all but the known winner, and the final 2 are the horses that finish 1st and 2dn in this race, plus the winner of race 6.
Thank you for this video! Really fun question to figure out! I didn’t look at the explanation part of this video so I would like to comment my thought process before I took a look. I applied a few concepts that are helpful when solving riddles or questions. 1. Breaking down into components 2. Considering extremities to draw insight I first thought of what would happen if we raced 5 horses? Solution is easy, the top 3 of the horse raced since there are only 5. Now what if we considered 10? We test both of these groups out but we can immediately realize that 2 tests aren’t enough, even 3 or 4 is unlikely. This because we can think of extremities. I thought of several scenarios in my head: Maybe group 1 is a group of well bred horse that are extremely fast, and group two is a group of horses that are extremely slow. Great then the fastest 3 horse would be in group one. But wait no that seems wrong, what if one of these well bred horses accidentally got mixed into the batch of slower horses? All of a sudden the fastest horse of all might be the fastest horse in group two. Insight: This means I have to test each group of horse to determine the fastest of each group, or there’s no way I can be sure. Insight 2: If I compare the fastest horse from each group I can maybe get a ranking for the top 3 horses! After running this through my head I realized that we would never have to test the 4th and 5th of this group again, since they weren’t in contention for the top 3. This frees up two spots for us to test! Insight 3: We no longer have to test the 4th and 5th of any group any more (Since the fastest horse will always be in the top 3) I then ran some more scenarios in my head. The next logical test would be to put the next two fastest horses (2&3) in group 1 (the fastest horse group) into the test. This way if the 2&3 from group 1 are ranked the highest then we’re good to go! But what about 2&3 from group 2? Let’s apply some extremities. Group 1 horse 1&2 are super fast but 3 ah geez there could potentially be several more tests because there might be hidden fast horses in group 2. I might have to test the 2&3 fastest horse in each of the top 3 groups… If there’s a way to add another spot for testing this would significantly bring down the number of test I need to do. How can I do this?… Wait a second I just realized something… We never have to test the fastest horse in the group 1, since it’s the fastest horse in a race of all the fastest horses of each group, which means it’s the fastest horse in the entire race! Insight 4: We don’t have to test the fastest horse in group 1, which frees up another slot for testing. Great since we can now test 3 slots (We still need to included the fastest horse from group 2 and group 3) What should we test next? We definitely want to test horse 2&3 from group 1 since thinking back to extremities they might be the fastest group containing all 3 fastest horse. The next logical candidate would be the horse 2 from group 2 as that’s the next fastest horse to test. Let’s run this scenario in our head to see if this works. - If the horse 2&3 from group 1 are the fastest, then we have the solution. Horses 1&2&3 from group 1 - If horse 2 from group 1 is fastest, but horse 3 from group 1 is slow, then it would be horse 1 from group 2 that is third. - If both horse 1&2 from group 1 are slower than horse 1 from group 2, then all of a sudden horse 2 from group 2 becomes in contention for being 3rd fastest horse. Since we’ve included that horse in the race we’ll still receive it’s ranking in relation to horse 2&3 from group 1. Nice we have that covered then - The last possible case that can now happen is horse 1&2 from group 1 and horse 2 from group 2 are all slow, then horse 1 from group 3 would be the third fastest! There’s no more tests to be done as we’ve considered all extremities, and this looks to be the answer! Let’s tally up all the races we’ve done. - 5 races to find the fastest horse from each group - 1 race of the fastest horse from each group - 1 more race to consider the top two horses from group 1 and top two horses from group 2 and too fastest horse from group 3. This totals up to 7 horses! Above was my thought process and I skipped to the peak replay in the video and found the answer was indeed 7! Happy I got the solution! Entire process took about 20 minutes which means I would probably not finish this question during the interview (As well I might be too nervous) But it was super fun to solve! Brb going to watch the video to see the thought process of the actual solution. Thank you for providing this video!
Wow upon watching the video drawing this out makes it a lot easier. I had process of elimination in my mind but was doing so progressively considering the next best candidates in the given scenario. Approaching it from purely a process of elimination method makes this much easier to conceptualize rather than have to think the scenarios through in my mind. Drawing and eliminating would definitely be the best way to solve for this, but not sure if interviewers would allow for that. All in all amazing video and a great piece of thought puzzle!
Good thought process, congrats! One thing though: if there are 10 horses, and we can race 5 horses per race, then we can identify the 3 fastest horses (out of the 10) always in exactly _3 races_ . Just have a try at this (much simpler) problem!
@@yurenchu You're right, if I had continue to explore this easier problem, I would have gotten insight 4 (We don't need to test the fastest horse) way sooner. This would have shaved off at least 5 minutes when answering this question. Good point!
I got 8 because I had a different interpretation of minimal. It takes at least 8 races to guarantee an answer, but can be done in 7 four out of five times. 6 races (five groups of 5, plus a "finalist" round) to find the fastest horse. You keep track of the 2nd and 3rd place finishers in each group. Whichever group the first place horse came from, the 2nd place horse from that group-stage races against the 1st place horses that remain (7th race). If a 1st place horse wins, then it is the 2nd fastest and which ever horse got 2nd is the 3rd fastest. If the second place horse from the group-stage wins, it is the 2nd fastest horse and the race must be run again with the 3rd place horse from the fastest horse's group-stage to find the 3rd fastest horse (8th race).
a simple way to approach this is understanding that the fastest 3 horses will be in the top 3 of any given subset of 5 horses. This means that if we can identify a subset of horses for which a particular horse would not be in the top 3 (proved by transitivity) then we can discard that horse. So after you do the 5 sorted horse groups, you find the order between their winners (6 races so far). All the horses slower than the 4th and 5th places from this last race can be discarded, together with their the 4th and 5th place horses as well (so 10 horses are gone). Then, all other horses that scored 4th and 5th place can leave as well. So we have 9 horses left. 1st place from 6th race is 1st place of all, so no need to re-evaluate that one. Now if you just try to attach the potential best score of every horse of the remaining 8, you will find 3 that cannot score better than 4th place. You are left with 5 potential horses which make for the 7th race
25 - 5 = 20 horses remaining via the initial race. The absolute best case scenario is that the initial 3 you picked were in fact the fastest 3. (Though given the information provided, you do not know for sure until all other horses are compared.) Thus they move on to be compared to the remaining. With that in mind... Race 2: 20 - 3 = 17 Race 3: 17 - 3 = 14 Race 4: 14 - 3 = 11 Race 5: 11 - 3 = 8 Race 6: 8 - 3 = 5 Race 7: The final 5. Thus you will know for certain which horse is the fastest with the absolute minimum races required.
I couldnt really come up with why I would need the 7th race(after 6 races and I knew I had at least one more race to figure out the top 3 but I could not really come up with how to match up 5 horses for the 7th one) and now I can say I know why. Thank you.
wow thanks for this answer i give it in my interview and now iam restricted to sit in any of the Google's interview😄...stating this is the dumbest posible answer anyone can give
@@pryo2460 I'm guessing you're the kind of person that yells at everyone when your Iphone Battery stops working, or your Electric Car starts to wear down, while shouting, "It's not broken! It was working just fine yesterday!" Jokes aside, but "Mechanical" doesn't mean "indestructible, or immune to wear..." it means, "Consistent Performance on Repeated Runs." Even two Ford 150's aren't going to perform the same forever.
Up until your last race I'm with you. You still need 1 more race because logically horses a2 or b1 must be in 2nd but that doesn't help for 3rd. There are still 6 possibilities. You need to race these 5 to determine all three. Therefore the minimum is 8
No race needed. I'd butcher 22 horses. Not only would the remaining 3 become the fastest by default but I could stack up on delicious horse meat and land the Google job for my out of the box problem solving.
If the Google Executives hire you, they may apply a similar method when it's downsizing time and they have to determine who their three most productive employees are.
Curious-I was never good at math, and I have no interest in solving puzzles like this myself, nor any confidence that I could arrive at the correct answer. (I don’t work at Google.) yet I enjoy watching videos like this and am pleased to know the answer once it’s explained to me.
It's a sorting algorithm. 5 races to sort them into a 5 queues of length 5, and 3 races to get the fastest from the head of each queue. Standard merge sort.
@@JohnWilliams-channel - But were looking for the 3 fastest horses. not the fastest - Example - race 1 in won in 60 seconds with the 2nd horse taking 61 seconds and the 3rd horse taking 62 seconds. All other 4 races are won in 64, 65, 66 and 67 seconds. If only the winners are taken through to the next round then the two horses running in 61 and 62 seconds will not get through. You need to take the first 3 runners (15) through to the next round of 3 races, after which (8 races) you're left with 9 runners. You need another 3 races to get the 3 fastest - 11 races in total.
@@martinkil50 So the first 5 races determine the order of the horses in each race. The 6th race determines who is the fastest among those 5. The 7th race takes 2 and 3 from the fastest group, 1 and 2 from the second fastest group, and 1 from the third fastest group. You don't need to race 1 from the fastest group because you already know it is the fastest. In the 7th race, the ones that come in 1st and 2nd are the 2nd and 3rd fastest horses respectively.
7 million views! Thank you! Here's a Microsoft interview puzzle I think you will enjoy. A cat is hiding in one of five boxes that are lined up in a row. The boxes are numbered 1 to 5. Each night the cat hides in an adjacent box, exactly one number away. Each morning you can open a single box to try to find the cat. Can you win this game of hide and seek? What is your strategy to find the cat? What if there are n boxes? Watch the video for the solution! th-cam.com/video/yZyx9gHhRXM/w-d-xo.html
I know this is a little bit late but i got a different result and i want to know if it is right.
My result was 6,because that in the same race that we used to discover the first fastest horse we could use to discover the second and third fastest horse.
Sorry if it is hard to understand, it's because i'm not english.
@@sandrathiel4475Sorry, no, you can't put more than five horses in one race.
You provided 7 million people with an inaccurate method.
@@MrJelle18 I was saying that,in the race that we discovered the fastest one,we could say that the second and third place would be the second and third fastest horses.
@@sandrathiel4475 How do you know the 3 fastest aren't in A.
If I race 5 horses at a time there's no way I can beat any of them, horses are fast
Depends on the race. Run them through an Army obstacle course. I'm guessing they'll get hung up on the wall climbing, rope swinging and belly crawl parts.
It also depends on the length of the race. Native American runners could outrun horses in an endurance race. People are willing to keep going when animals would quit. So, if you're in shape for a marathon, you'll probably win.
@@flatebo1 Humans have an innate advantage in an endurance race vs most animals our species evolved to hunt critters by running them to exhaustion, that is to say we are naturally built for persistence hunting.
Truer words were never spoken
@@flatebo1 If the race is in high temperatures, then humans have an advantage. In colder temperatures the advantage is slimmer or maybe non existent.
@@seraphina985 have you ever rode a horse? He is really enduring, why do you think he was used as a transport mean in the past? Even if its an endurance race he will leave a long distance with the human so he he could rest and start again, but don't worry he will not get tired before minimum 5 hours
Pick any 3 horses and destroy the remaining 22 horses. These three horses will be the fastest.
@@hayn10cause they are now 100% of the horses
I think that's how they hire people to some companies in Germany. This is why German online services suck.
Reminds me of Stalin sort :D
You score high in Machiavellianism. Congrats. ♥
😂
I got 6, then realised i hadn't considered that the second fastest might be faster than another group's winner. Nice one
Same 😐😐
Same
Same! I just thought the second and third of the sixth race would also be the fastest 🤦🏽♀️
what i dont get is why we need 7 races :
we must do five races for the five groups and from that we have found the 5 fastest horses of them all
secondly we just race those five horses and the first three to finish are the fastest three horses right ?
so that a total of 6 races !
P.S : no where in the question does it state that you need to know their ranking aka whos fastest of the three ...
@@shadi3993 But if the 3 fastest horses are in the same group your method will only identify one of them.
Here is how you can really solve this problem with 6 races: Let 5 horses race and label the 3 fastest horses from that group A, B, C. Assume that C is the 3rd fastest horse of all 25 horses and proove that by letting C race against the remaining 20 horses with 5 more races (6 in total by now). In the unlikely case that C is indeed the 3rd fastest horse, you've identified the 3 fastest horses (A, B, C) with 6 races. This is'nt an efficent method because it requires more than 7 races on average but sometimes it can solve the problem with only 6 races.
Yeah this was great. I was having a hard time until I saw you group them in to a,b,c,d,e based off of the rank of their race. I was getting stuck on the three fastest horses being in the same race initially but the re-grouping did the trick. The visual really helps.
Feel you, i was stuck at a minimum of 11 races , because i wasnt regrouping and i thought id always have to let the top 3 of every race continue in case the 3 fastest horses happened to be in the same race at the start.
Outcomes are dependent on competition. This is a software developer question written in a bubble. And he didn't specify time , vs, outcome.
Race six runs the winner of each group, but it takes a minimum of two races to remove all the second and third place finishers. Therefore his solution is wrong.
It's not right.
I'm still a little confused. How can you order the groups based on how fast they were if you don't know their finishing times?
@@sasquatchrosefarts What do you mean? After race 6 you know no horse behind the third place horse can win, 1 horse behind the second place horse gets a chance for third place, 2 horses behind the first place horse get a chance for second and third place, the winner of the winners definitely is first place, leaving 5 horses to be checked so we finally know the second and third place.
When you identify a horse is slower than a horse that turns out to be slower than a slow horse then you also learn something about the first horse even though you didn't let it race again. Horses can be identified to be slower after a later race. If I misunderstood can you explain why you consider the solution to be wrong?
@@esco8778 Well you order the groups based on the place their "winner horse" made at the "winners race". So you have the 5 races at the start, after that the 5 winner horses will race each other. After that you order the groups by the finishing order of the groups fastest horse in the "winners race".
So if the winner horse of group C also wins the "winners race" group C will be the "fastest group".
Google: Which 3 of those 25 horses are fastest?
Meanwhile on bing: Leave only 3 alive
LMAO
LOL
That leaves you with the slowest three. You would have to have four left to give it a possibility
@@stevenmorris3181 but they would be fastest three too, right?
@@momamilosevic2465 Accidently killed the top 22...These things happen
I realized pretty quickly that 6 races isn't enough, at which point I decided it's to complex and might require like 20 races or something.
Glad to see such an elegant solution, thank you!
So close
That was my exact chain of thoughts
I got 11 races lol
Why isn’t it 6? When you run the 6th race full of the winner horses, the 1st 2nd and 3rd places would be the fastest horses, right?
@@galacticlava1475
2nd place horse in 6th race might be slower than second place from the race the first place horse raced in.
for all we know, that specific race might have consisted of the 5 fastest horses in the herd.
thats why we take the 2nd and 3rd horse from that group, because even if 2nd place horse in race 6 is faster than 2nd place horse in race with the overall fastest horse, it may still be slower than 3rd place horse in that race.
you consider the 2nd place horse in the race producing the 2nd fastest in the 6th race as u want to find the top 3 horses in speed, as 2nd place horse in 6th race might be faster than 2nd place horse in race that produced the fastest horse.
Lastly, u include no3 from 6th race as all these extra horses included can still be slower than it, and if so, u still have ur fastest 3.
You race 5 horses, sell the slowest one, and buy a watch.
The rest is trivial
As if the buyers are on standby.
Best answer!
Expensive watch 😂😂😂
@@alessioandreoli2145 of course, a very accurate one, with stopwatch function included 🙂
this is a question not a business....
When you showed step three I was confused at first, then after a few seconds my brain understood and it BLEW my mind, what a great video
In a Google's interview the better answer should always be: Google It!
Hahaha
U are in
Someone hire this man
Ok then the answer of Google will be
: Plse Google another job for urself 😂😂😂😂
I agree
Last season in F1 we had 20 drivers and it took 17 races to identify the fastest 3 drivers
This is since they are human and not mechanical horses... so their times differ from race to race.
@@you2uber530 its a joke
It took 0 races
@@you2uber530 r/whoooosh
Lmao
for people getting 6 races, we’re trying to find a method which guarantees the top 3 horses will be found. after the first 5 races, there are 15 horses which could still potentially be top 3 overall, and after the 6th race, there are still 5 in contention, including some of those 15 who didn’t win their initial race.
I do not give a crap it is six for me
@@ilikefarting edgy
@@frommelow exactly how
@@ilikefarting "I dont care if i was proven wrong i still think im right"
this is why humanity has SO many problems
@@deemcgann1695 is this math problem a 1st world problem? also it was an obvious joke
I know I will never work at these kinds of places, but to see the thought processes in these puzzles is awesome. Training yourself to look at the same real world problem in different perspectives to solve real world engineering/ self reliance problems are invaluable. Great video
Never say never 😊
@@Neil.Menezesthats an oxymoron
@@pickleism253 fine, never say never except to say the phrase 'never say never'.
This was before logic and rational thought was deemed racist. Now states like NY are outlawing 'tests' like this in the pursuit of 'equity' and we're slowly starting to fall behind other countries like China.
As an employer, this is the answer I want: "We need a watch so we won't have to waste time with unnecessary horse races"
And it is open to interpretation, so some will interpret it in a way so you can label the horses and get 7 races, others will not label them and get 11 races. I would think a good answer would also be that the instructions are not complete
If you are looking to hire a programmer that's definitely not the answer you're looking for. If this were a simulation it would take less resources to program this solution in than to program in a clock. Programmers have to always think abstractly to find the most practical solutions.
except you actually make more money having more races, the house always wins.
@@bro748 That's also a very good answer. Also, if I hired a programmer, the only reason I'd have them out racing horses without proper equipment, would be as a punishment. Or maybe as a reward, depending on the programmer.
@@bro748 If you are looking to hire a programmer, you want to get a solution that does not blow up in your face when you get a 26th horse and the algorithm is just not working anymore. So you should phrase this as a more general problem with N horses. And then it gets interesting whether you want to find a generalizable algorithm that performs well on both low and high numbers or something that switches in between.
Adding a clock scales nicely O(n), which is the best you can get with this, so this is actually one of the best answers. :P
I was getting 9 as a first effort but then as soon as you said 7 I was able to figure out how to get 7… It’s truly wonderful how much knowing that something can be done can influence your ability to do that something
Same here
I did the same thing as well
exactly the same words
Just like our full potential as a living being. Very few people know this and it then makes it impossible to achieve it until you are taught it by someone who has achieved their full potential. Most believe it is impossible only because they don't know how.
"Knowing where the trap is-that's the first step in evading it" ― Frank Herbert, Dune
Sell all but 3 of the horses….
Those 3 will be the “fastest” horses you have. 😎
0 races needed.
Perfect score. 💯
Tell the horses they're being sold, and the three that don't get caught are the fastest.
#OrwellWuzHere
"And then they burst out in laughter."
When you apply to Google, but it's economics dpt and not IT
This is elon musk
I came up with 8 races and proved it using pennies as horses. I didn't consider the 7th race could determine both the 2nd and 3rd fastest horses by eliminating the entire field of horses that only had 1 winner (race 1 -5). Thanks for posting.
Even i got 8 as my answer
I got 8 as well, but then when I saw the actual solution was 7 I immediately noticed we repeat the 7th and 8th race with the bottom 2 horses that have absolutely no hope of ever winning a top spot, and so worked out the best solution from there. So I worked out how to do it in 7 after seeing the solution was 7, but before seeing how to do it.
@@MrSupdup for some reason i kept looking for the top 5 fastest horses haha
needed them place bet odds i guess
I also got 8. It is easier to find a solution that is not optimal, but that is fine in computer science. After you found a solution that works, you should seek to find a better solution, if necessary. 👍
I got 6, but I was wrong. I assumed the first 3 winners of the 6th race were the 3 fastest, without considering that they hadn't raced yet against those of higher level
I think it also depends on who is keeping track and actually watching the races. Alice or Bob would be able to figure it out. Charlie is either selling popcorn or shoveling the stalls.
the answer he gave is not correckt! The problem is that you dont have a time/ watch nor a distance! If you let 5 groups run, and you take the 1st. of each group, you can not be sure if these horses are one of the fastest 3. 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! . you have to have a constant to really get the 3 fastest! My logic: So you let the first 5 race, then you let the first second and third place on the track and get 2 new ones in, every race the 4,5 will be replaced. with this method you have always a constant for first, second and third place without needing a watch ! each race, 11 in total , will naturaly eliminate 4 and 5 place ! imagine this: lets say the first group are the 5 slowest of all, so the slowest up to the 5th slowest of all. in the second race the 4th and 5th place gets replaced with (in this simplyfiyed case)faster ones, and maybe one is the fastest of all and the other one the 2nd fastest of all. they will be 1st and 2nd place of the 2nd race and they will stay on this position. the 3th will be found after all other races are finished. You can switch the start situation, that the first 5er group have two of the fastest of all in it, so the first and second place will be set after the first race, and again the other races and just to find the real 3th place.---- i think its 11 races ! 😃
hahahahaha~
Goddammit Charlie! Who keeps hiring this guy?
@@crashoverwrite5196 > 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh!
No. If you look carefully at the solution, the groups "a, b, c, d, e" are named *after* the 6th race. the winner of group a is the 1st place of the winners, the winner of group b is the 2nd place of the winners, so by definition a_1 > b_1 > c_1 > d_1 > e_1 - and then, you have a tree from the winner, you only want the top 3 so you can eliminate any that are 4th or more from the winner, and you are left with exactly 5 horses to race and find the 2nd, 3rd overall
@@sodiboo You dont know how fast they are! so my asumtion is valid. You need a fix point for the 1st,2nd and 3rd place. my comment was based on the crux, not the solution he gave.
I am not getting smarter, i am just upgrading my memory over puzzles for when i do a job interview in like, four or five years
If they ask questions like this you do NOT want that job.
@@TheRealInscrutable : Agreed. Speaking as someone on one of Google's hiring committees, we don't ask interview questions like this. :)
Job interview questions are simpler and shorter. Tom has 3 apples and Mark has 2 apples. Calculate the distance between Earth and the Sun
@@LivingAmnesia the answer is 7 cars
@Dpg Dpg You didn't calculate it, you looked it up. Sorry you don't pass
In order to calculate it, you must take drag a line from the edge of the earth to the edge of the sun
formula for this is probably something like
t=size of top group
n=number of horses
c=race capacity
r=number of races
Assuming t
To the people saying 6 is the answer
What if the 3 fastest horses are placed in the same group by chance
Do you get why there are 7 race needed now?
If so why removing group e and d would be correct since you dont have a watxh
Simon REEVES after racing the 5 fastest horses from each group you can automatically eliminate these 2
Because every horse in group D or E is by definition slower than top C which is AT BEST the third fastest(top B and top A beat it in a race). So at best every horse in D and E can be fourth fastest and can therefore be eliminated.
So if following this example the times for slowest to fastest in each group are as follows:
A: 10, 9, 8, 7, 6
B: 14, 13, 12, 11, 10
C: 15, 14, 13, 12, 11
D: 16, 15, 14, 13, 12
E: 17, 16, 15, 14, 13
How is it valid to eliminate a3-a5 as being slower than b1?
You're not eliminating A3, you're eliminating A4-A5, B3-B5, C2-C5, all of D and all of E. Which will always be valid. You're not eliminating them for being slower than B1, you're eliminating them for being slower than AT LEAST 3 other horses. The final race is A3, A2, B1, B2, and C1 since those are the only horses left that aren't confirmed to be slower than at least 3 others.
So something we talked about in economics the other day is how if you take too much time to solve a problem in the most efficient way it can be more costly than just doing the inefficient way that instantly comes to mind. The answer I came up with was 11. I know it’s not even close to 7 but if I was able to have a system ready in 10 seconds that works I’m still proud of that answer
Edit: very happy with the conclusion of the video though. Super cool thought process!!
But then again, if you spent a bit longer thinking more efficient solution you would save 4 races.
That's 20 races you would have saved those mechanical horses from doing. If you do this more than once the maintenance costs are going to pass your thinking time.
well, this makes sense to me, but i think that if u create the best solutions u will be faster to create the best solutions next time and everytime, and maybe just at the start is harder, maybe
Depends on the context. If it's a one time thing then sure but if you have to compare horses thousands of times then you have to use the better answer
I think he is wrong, he would not be hired by Google. (About the answer in the video)
I think he assumes that all horses finish at equal time intervals. The fastest horse, without any timing available, doesnt say anything aboit the slowest horse.
The horse that finished 2nd to the fastest of all horses (the fastest group) could still be slower than the horse that finished 2nd to the horse that finished #5 in the 'race of winners'
So without also determining which are the slowest horses this is just assumption.
I'd say one need at least 8 races therefore.
11 is making sure anyway. Cross reference and you can make the whole top25.
@@Coen80 With 7 races you always identify the three fastest horses
The mathematically optimal answer shown in the video is satisfying to discover! The use of this method seems to be dependent on the specific numbers of total horses and horses per race presented in the problem, though...
While trying to solve the problem, I came up with an algorithm which has the advantage of generalizing smoothly to any variation of the problem with M horses in the pool, N horses allowed per race and K spots at the top of the field, where K ≤ (N+1)/2. Here it is:
Start: Have a group of untested horses, and a "leaderboard" with K spots. All M horses start in the untested group.
Place N untested horses in the lineup for the next race. Run [Race Type A].
[Race Type A]
Race the horses in the group; place the top K on the leaderboard, in order, and throw out the (N - K) horses at the bottom.
Now add the horse in Kth place on the leaderboard, and (N - 1) untested horses, to the racing group. Run [Race Type B].
[Race Type B]
Run the race with the current group. The next step depends on the outcome of the race:
If the horse currently in Kth place on the leaderboard wins the race, eliminate all the other horses in the race and set up the next race with the Kth horse and (N - 1) new horses.
No change to the leaderboard. Run [Race Type B].
If the Kth horse comes in 2nd or worse, eliminate the Kth horse and all horses in the race who were slower. If K or more horses beat the Kth horse, add the top K finishers to the next race;
otherwise, add all horses who placed above the Kth horse.
Add the other K-1 horses on the leaderboard to the race. Fill the remaining spots in the race, if any, with more untested horses. Run [Race Type A].
When no more untested horses remain, the leaderboard contains the K fastest horses.
I ran a Monte Carlo simulation of this algorithm with 10,000 trials, and for the values given in the problem (M=25, N=5, K=3), the expected number of races is just under 8. Not bad!
This is interesting!
What does a simulation find in the situation (M=25, N=5, K=2)?
By the way, the approach of the video's method isn't necessarily the optimal one though. For example, in the case of (M=4, N=2, K=2), the video's approach would suggest that 4 races is optimal. However, it's relatively easy to find a method that takes 3 races in 1/3 of all possible scenarios, and 4 races in the other 2/3 of scenarios, thereby resulting in the optimal method that requires 11/3 = 3.6666... races on average; which is more efficient than 4 races. And maybe 7 races is optimal for the case finding the Top 3 out of 25 horses, but the video failed to give a solid proof of it (the "proof of minimality" in the video is flawed).
LOL, your generalized algorithm actually results in the optimal method for the (M=4, N=2, K=2) case! :-)
@@yurenchu when I run your first scenario, I get right around 7.5!
Locking in my answer: After racing 5 sets of 5, you can eliminate the 2 slowest of each set of 5. Then if you race the tops from each set, you can eliminate everything from the worst 2 sets of 5. You now know the fastest. The remaining 2 horses from the set whose winner ranked 3rd can be eliminated and the 3rd place of the set whose winner ranked 2nd can be eliminated, leaving the battle for 2nd and 3rd between the 2nd and 3rd from the set whose winner was the best, the 2nd place horse of the 2nd place among winners, and the 3rd place among winners. Race those 5 horses, find the top 2 and they are your 2nd and 3rd. 7 races total.
edit: nailed it :)
Edited comment. Seems legit, lol. 6 is the minimum amount to find it by luck. 7 for 100% certainty. Not bad, though.
0 or 1 is the minimum amount to find it by luck lol
I'm the interviewer, I'm now wishing I'd never asked this question after hearing 27 variations of how to solve it. It's late Friday and I want to finish work. . . . . . .First one to tell me, 'Sell 22 of them, keep the cash!' Gets the job! I don't care, I'm retiring next week.
I said shoot 22 horses but this is so much better!
Hey its been a few weeks. How is the retirement going?
@@apollyon1 So did I!
What has happened about retiring next week? Are you so busy making the papers ready that you forgot you had announced your retirement publicly on TH-cam?
@@apollyon1 ingenious :)
I knew it with cows, that's why I couldn't solve it.
usaco?
Eduardo Torres lmao
With cats, the problem is even harder than with cows!
LOL
The hamster version was straightforward....horses don't make no sense!
This was actually a pretty good case of problem where you can start from easier examples to get the solution. I took «fastest 2 of 4 with 2 racing at a time» and «fastest 3 of 9 with 3 racing at a time» which brought me to idea of elimination in no time.
What was your optimal method for "fastest 2 of 4 with 2 racing at a time"?
And for "fastest 3 of 9 with 3 racing at a time"?
Running through this pretty quickly, I got 11 races. 5 horizontal, 5 vertical, then a final race to determine the order.
Love the logic in this. Shortest route to the best answer.
Which horses would you pick for the final race?
By the way, the order of the three fastest horses is not required.
@@yurenchu I was over complicating the puzzle. It makes it a lot easier when you are allowed to reshuffle based on performance.
@@ZimCrusher Sorry, but what are you talking about, "when you are allowed to reshuffle based on performance" ? And first you said "Shortest route to the best answer", and now it's "I was over complicating the puzzle" ?
And why aren't you simply answering my question: which horses would you pick for the final (= 11th) race?
@@yurenchu When I ran my solution, I would always end up with overlap.
Meaning, There would be horses that won both vertically, and horizontally, in the final count, so there would only be 6 horses remaining. I would run the horses that won both races, and then just fill in the race with 1-2 of the single entries. This always gave me the top 3, but I only ran it 100 times.
Looking, now at my code, it should have given me a few end results where one of the top 3 was left out.
So... my solution fails as a perfect solution, not even counting that I needed 11 races, to their 7.
@@ZimCrusher Thank you for your reply and your explanations.
Ah, now I get it. Previously I assumed that when you said "vertical", it meant that after the first five races, the first place finishers raced against eachother in race 6, the 2nd place horses raced against eachother in race 7, the 3rd place finishers raced against each other in race 8, and so on. Because that was an approach that was suggested by another commenter that I vaguely still remember. I didn't understand that you meant "vertical" as in how these 25 horses were arranged in a 5-by-5 matrix from the start, before any races were run.
That makes the analysis interesting but much more complicated though. And yes, it appears that there would be scenarios where one of the Top3 would be left out (in 11 races), since after the first ten races, it's possible (for example) that the #3 fastest horse overall has lost both of its races (and hence dodges "detection"/won't be selected for the 11th race), while five other horses have won both of their races.
Anyway, thanks for your reply.
I came up with the optimal solution in a few minutes with pen and paper, but I guess it's easy to get stuck if you miss some piece of information.
I thought it was easier to think backwards: first you definitely need 5 races to race each horse once. The two slowest horses from each race is definitely not part of the top 3.
You are now left with five groups with three horses (15 in total). You don't want to race them all against each other, so you can rank the groups relatively to each other by racing the slowest or the fastest in each group. Since we're looking for the fastest ones, intuitively it makes more sense to rank by the fastest, so we race the fastest horse in each group in the semifinal.
All the horses in the two groups represented by the last two horses in this race will all be slower than the fastest three horses in this race. We're left with three groups, with three horses in each (9 in total).
Some observations at this point:
- The fastest horse is identified, as the fastest horse from the semifinal
- There are three ways that the three fastest horses can be arranged into the three fastest groups: the top three from the fastest group, the fastest horse plus the two fastest horses in the second fastest group, or finally the fastest horse in each of the three fastest groups.
This gives us 6 candidates for the three fastest horses. Realizing that the fastest one is already identified leaves us with five horses to race the final.
The two fastest horses in the final are the second and third fastest horses.
Alternative solutions:
- 1 race: Race 3 randomly selected horses. The other ones have never competed so their time is undefined.
- 0 races: Shoot 22 horses.
Professor Layton ass solutions
thats dark men
I got 8 races in 10 seconds and no paper...
@@thomgizziz Same
I got the same result with the same reasoning, except note that when you say "there are three ways..." there are actually four; you could also have the fastest horse, the second fastest horse from that same group, and the fastest horse from the second fastest group. That doesn't change anything about the rest of your explanation though :)
I made it seven, but it was a bit of a guess. I got as far as racing five groups of five and then racing the winners, giving six races. After that I figured one more race should do it, but more by intuition than reasoning. The step that eluded me was that any horse beaten by three others could be eliminated, although that seems obvious, now you mention it. I think I would have got there eventually, but it's easy to say that and my working would most likely have involved some extra unnecessary steps. Thanks for the clarification 🙂
This is something I learned in grad school. For any top-N problem, the tournament algorithm produces the minimal time solution, same O-notation complexity, but lower constant factor due to decreased pairwise comparisons.
The general extension of this algo would have been an excellent interview question with a runtime and proof of completeness. It felt good to know I got this one right when I did it.
Google doesn't actually use these sorts of logic puzzles in interviews. At least they haven't for the last 20 years or so. They ask algorithmic/coding questions, system design questions, questions that check technical knowledge and the like. There are lots of videos posted by Google about how to prep for a Google interview. But tl;dr, re-read Introduction to Algorithms (AKA the mobile book).
This _is_ an algorithmic question. To be more specific, a sorting question.
Ehh it isn't far from common questions I was giving people 5 years ago in google interviews. They moved away from the how many rats in new york city type of question pretty quickly. But logic questions are common. By the time I was interviewing people we were generally trying to make sure all the logic questions included a degree of psudo code as part of the answer. But in spirit this problem is pretty close to what we would be asking.
Something i think could be explained as i didnt initially think of it and other ppl dont seem to have noticed is the fastest horse of a given race could still be slower than the slowest horse in another race. Just depends on luck of the initial groups
I was thinking about this too, but with this method, it won't matter. Even if the horses are arranged strictly by performance (the slowest in group A is faster than the fastest in group B), it will just mean that the winners of race 7 (2nd and 3rd fastest overall) will all come from group A
Better to put forward with timings .... I mean minutes and seconds
There is another problem in every race the horses are randomly asigned and you don't have the time so by that definition in one of the groups you can still have the 1 fastes hourse and 2nd fastes from all 25 hourses, but by this method of elimination you have already decided that the secound fastes hourse is no longer competing and the 1st fastes hourse is compeeting to the once left from other groups.
Exactly. In some competitions, the best of the best go straight to the finals, but it does not mean the newcomers aren't stronger.
@@mitsuriKoi which is why the whole mechanical horse with a pre-designated time that always stays the same made this make a LOT more sense for me!!
Oh wow! I actually got this right. I almost never get any of your puzzles right so I’m beyond thrilled! Love your channel!
2 million views! Thank you!
Thank you!!
Can you please change your theme to a black board
Thankyou
What if the 5 horses in group "a" were actually faster than all other horses ... How you will solve it without a watch
I guessed 7 does that count
@Moh Taw,
- "What if the 5 horses in group "a" were actually faster than all other horses ... How you will solve it without a watch"
That's exactly why horses a2 and a3 also participate in the seventh race (along with b1, b2 and c1), which they will win in your scenario.
Love your method. I somehow got 12 by ruling out the horses that were not the fastest.
You'd get to 10 that way, but I did the same..
(25 - x * 2 = 5, since you need final 5 to race. x equals 10.)
This only works for spherical horses in a vacuum.
best to make them frictionless, spherical horses in a vacuum :)
@@backwashjoe7864 lmao how do they run?
And all collisions are elastic
ideal horses too, so individually they have no volume but occupy a finite space together.
They also do not attract each other so little ponies won't be made
@@backwashjoe7864 I’d argue that being frictionless and in a vacuum were redundant, but…
Instead I’m going to add that they should also be made up of non-baryonic matter so as not to be affected by virtual particles.
Frictionless non-baryonic spherical horses in a vacuum.
I just want to say, your question is exponentially better than the common interview question. Me sitting here with tired horses, one fell in a race....
there's nothing exponential about this. Exponentially doesn't mean "a lot more".
@@fmobus i bet it gets girls at the club reeeal hot when you tell them that
@@fmobus you do understand what an exponential equation looks like right? Calling something exponentially better is in comparison to calling it linearly better, where something exponentially better reaches its limit faster than something that reaches its limit linearly. So “exponentially better” means “a lot better” and “exponentially more” means “a lot more”…
@@fmobusAre you the type of kid who tries to correct a teacher?
It’s a classic quant question
I was originally going to ask why 6 wouldnt work, but the visuals really helped me find that out. Great video!
@@jasonbernard5468 it’s not a solution if it doesn’t work in all cases
@@jordantyler148 yea my ideaonly works in one case anyhow otherwise it needs 8. I was wrong when i commented before
@@jordantyler148 actually Im not sure, imight have been right, but not the way i thought. You say it isnt a solution unless it works in all cases, but what if i had a method that gives the answer in 6 rounds if and only if all top 3 horses are in the first group, and gives it in 7 rounds if not? Im not sure if I have such a method, but if I did it would be a better answer than the video, would it not?
@@jasonbernard5468 It would be interesting if you had a method that sometimes worked in 6 rounds, but occasionally needed an additional round, but only if you knew if it was done after 6 rounds, not if you do the 6 rounds and you dont know if its right.
@@jordantyler148 There is a method that works for all cases and in best case is only 6 races, but worst case 11. It does not involve doing 5 races with all horses like this. You do an initial race which gives you an initial #1, #2, #3. You take you 3rd place and race it against 4 new horses. If any are faster than current #3 then you race the fastest 3 of those against your current #1 and #2, giving you a new set of finishers. And continue with whatever the current #3 is. Best case, they are in order and you do 1 initial race plus 5 additionals where none are faster that that first #3, so 6 total races. Worst case they are in reverse order. and you will have to re-race after each of the 5 races, so 11 max. The question is to find the minimum, not the most optimal solution. So this would be a "better" answer.
The fact that you specified that each time had to be different is what gave it away for me. But, that also made me think, without that detail the original puzzle would be almost impossible if you take into account that horses could finish at the same time and drawing for places.
I think the key thing to think about is that A1 is automatically in so you are now looking for the fastest combination to fill 2 spots. So if there are only 2 spots then you know that anyone in group D or E is out because there just aren't enough slots for them. Everyone in D group is slower than D1 and D1 is slower than C1. So the LONGEST possible path is A1 to C1 (because B1 will always be faster than C1. This is also why C2 is out of contention, which threw me for a second). The shortest possible path is A1 to A3. A1 is automatically in. You just need to test the viable permutations of the fastest 3 horses. So their are 4 possible outcomes that include only the 3 fastest horses. They are:
A1, A2, A3
A1, A2, B1
A1, B1, C1
A1, B1, B2
So if you ignore the A1s since you automatically know they are automatically the fastest of the fast, you get the horses you need to test against each other being A2, A3, B1, C1, and B2. That's 5 horses which works out perfectly for a 7th race!
You missed one. A1, B1, A2
You have no way of knowing if any 2nd place is slower then anyone but your 1st and 1st places above your group. For all we know E2 and even E5 can be faster then A2. From racing initial groups and winners you cant derive rest of field. You do not know times so there can be massive diference between 1st and 2nd places. Dont forget that initial groups are random.
Edit: nwm, it clicked for me after i read @frorkbrunk148 comment.
@@noelmullankuzhy927 he said A1,A2,B1. In his explanation order doesnt matter, he is simply stating all sets of three possible candidates.
I'm so happy i managed to solve this on my own before watching the video 😄
I think Presh Telwalker's explaination is better.
My solution was to grab 5 horses, race them, put the slowest two aside and grab two more to race off against the fastest 3 so far identified, after this race, the losers will be put aside and two new horses will face off against the fastest three from the second race, etc.
Not particularly quick, but since the horses won't get tired, you will eventually end up with the three fastest horses
that's the solution i got. it's only 4 races more than needed, so I'm still proud of myself for coming up with that solution.
@@haydenhuss8758 you just do sets of five and then race the winners of each set for a total of 6 races.
this works because each horse will be equally as tired since each horse will have had one race.
@@fayt9121 that doesn’t work. Lets say the second fastest horse was in the same heat as the fastest horse of all 25 horses. Then the second fastest horse would never be included in your final (6th) run.
@@Macarthurmaintenance this is true. so you are saying you have to race a total of 8 times since you want the 3 fastest horses right? you do your first six to find which one is the fastest and then you race second and third place against the winners from groups 2-5. I get that. And with this hypothetical, its possible that the horses don't get tired either. Ill be honest I cant put my finger on it but something's bothering me about this.
There are ways to learn this in 0 races. Consider disassembling one horse, reverse engineering its software to find where the horses movement rate is located, then hack the other 24 horses and learn their rates without the horse moving.
The question is "The three fastest horses" not "Rank the horses by the fastest" Another way is to destroy all but three of the horses, and then you automatically know the three fastest horses.
Technically correct, the best kind of correct.
For machines... Yeap.
"...destroy all but three of the horses."
*hold up*
@Heberth R. Vc aqui? Pensei que só assistia o Tadeu
but how do you choose which one to destroy you don't know their speed relative to other horses and hence you cannot put a threshold
I paused the video after hearing the instructions and after about 7-8minutes I got it right. Super cool puzzle
Anyone that can use the logic this guy does to answer an interview question like this is probably too good for the job, anyway.
I dont really think so maybe he is or maybe he is not
It's a programming problem, ie why Google would ask it to a potential employee. It doesn't really matter what horse is the 1st, 2nd, and 3rd fastest, they're trying to get you to come up with a problem-solving technique to identify what those horses are. Programming is all about developing these techniques, the actual numbers/results don't matter so long as the techniques are correct.
@@digiquo8143 Agreed. There are all kinds of videos on you tube (including several other of the 25 horses problem) that pose intriguing puzzles that challenge your brain to think, find possible solutions, look at possibilities, and come up with sound techniques that will work in any case.
Someone else here mentioned six races, and when I worked through his logic, I found out that he was in fact correct, but it only worked in 2 possible cases, both of which were statistically insignificant. The correct technique, as shown in this video, will hold up rigorously for all cases.
@@digiquo8143 results matter if there are many results, i.e. many applicants for 1 job
@@nobodyknows3180 nah man
I was started to write a long comment throughly explaining why I disagreed with your answer. I read through the comments before responding to see if others came up with the same conclusion. Upon reading those comments, others had realized what I had, and explained how they were confused and why your answer made sense. I see where I was wrong, after reading the comments.
If the 4th, and 5th place horse from the the 6th race were the fastest in their group, that entire group is eliminated. Even the 3rd place horse would be the very minimum possibility. Excellent mind puzzle, made me think thank you.
I was starting to do the same - only when I scanned through comments I was only surprised that everyone except me was in agreement. If the horses are divided randomly into even groups of 5 - how do we know that all of the top 3 are not in the same group and therefore 2nd and 3rd place are not automically incorrectly eliminated?
No it actually is not. On placing yes, but with actual times it can be very different. For instance A1 can run 1min but A2 needed 5min and the whole group E can still lie between them
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now but they got eliminated so can't race horse 3rd place so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
Shoot 22 of the horses. By definition, you will be left with the 3 fastest.
That's a tad psychotic, but damned if it isn't the sort of off-the-wall answer Google would hire you for.
It was 'RACE the horses', not 'ERASE' !
You had one job......
@@DreadX10 race horses in sets of 5 and kill the ones not 1st place, 5 races.
Race remaining horses and kill 5th and 4th place. 6 races.
You are now certain that the 3 horses you picked are the fastest of the original 25.
Got to laugh at this one.
@@ozzygilliam9194 ...but two or three of the fastest horses might (by chance) be in your group of 5, so then you would have shot one or two of the fastest horses.
you could race them in groups of 5 and the two slowest are retired (see Blade Runner).
Interesting puzzle. I didn’t initially find the explanation very helpful, except it made me question my initial answer until I could work out the solution. Good stuff.
I get it, but jumped to the initial conclusion of 6 races. I’ll say that I knew I was wrong and that I was missing something.
Good lesson here, I’m glad I watched.
i did the same thing
i also end with 6 races
I was about to, but then I thought "what if all 3 fastest horses is in the same group? This can't be the solution." I couldn't figure out the right answer though.
Mäx-Tick absolutely not
Sorry, Mäx-Tick, but someone with a background in math posted a solid proof in this comment section 8 months ago, showing that it's impossible to design a method that is guaranteed to identify the three fastest horses every time in just 6 races.
I was wondering how you could find the 2nd and 3rd fastest overall.
The other method I came up with was more of a slider and would require 11 races, which works but isn't minimal.
(Line up the horses, race the first 5, keep the top 3, add the next two horses, race and repeat)
That was my first thought too
I would race 5 groups of 5 and aswell remove to two slowest in each. Leaves 15, repeat, leaves 9, then 5 and of those it's the fastest three.
11 races
(5 x 5horses, 3x5, 2x 5, and last race with 5)
@@aramisortsbottcher8201 Wrote out a very similar thing about a day after you did. I just continued to take the top 3, even when it left we with 9 instead of 10. When I got to 6, I ran one race with 5 and left one behind. Then ran it again with the last horse eliminated and the spare 6th plugged in. For a small touch of extra certainty.
@@robertdavis5693 I first had this idea too, but when the point with nine horses was arrived, I raced the first five and after that the next four, but filled the fifth slot with one of the previous race. That way I could sort out two of five instead of one of four horses. This left me with 5 instead of 6 horses, so they all fit into one race :D
Came up with the exact method
I was getting 9 races:
- 5 races to get the winners. Each race produces a 1st, 2nd and 3rd place
- 3 races to find the fastest 1st place, 2nd place and 3rd place of the groups. This race produces the 3 fastest 1st places, 2nd places and 3rd places
- 1 final race with the 3 fastest 1st places, the fastest 2nd place and the fastest 3rd place
It was great to see it was doable in 7 though. Great puzzle!
(haven't finished yet) i was thinking 6 but 9 would be more accurate
my idea was just race them 5 times and then race the winners
@@shadow-faye no coz loser from some group can be faster than fastest of another group
@@KUPSZTALSON999 that is why i said 9 would be more accurate, yes
You have a mistake in your logic.
This is damn good, man!
Until I saw the visual elimination and the surprise at the end (that we don't need to race again the fastest horse) I couldn't wrap my head around it.
Thank so much!!!
I had come up with 9 initially, but knew there had to be a smoother way to do it.
Putting my thoughts into your nomenclature, I obviously started with 5 races. Then, I knew the bottom two from each race couldn't possibly be in the top three fastest, so they were eliminated. I'm now left with fifteen horses, A1-A3 to E1-E3.
My thought was to take A1-A3 against B1 and B2. Take the three fastest from that heat, and run them against C1 and C2, and so on. Assuming you get lucky enough to not have to re-trial with any of the third finishers from B through E, you could get all the heats done and find the three fastest horses in 9 races. Obviously, the issue would arise if both of the two from the new group beat all three from the previous heat, but that would only end up adding a maximum of one additional heat, to a total of 10 races.
I dismissed the idea of running the top finishers against each other too quickly, as I figured that only finds you the absolute fastest, and you've just spent a race only eliminating one option. I wish I had sat on that longer; I may have realized the implication of how many more horses you could eliminate by that one race.
Great little thought puzzle, and I'll learn to not dismiss ideas so quickly next time.
Exactly the way i tried to solve it
After watching this video, horse neither looks or sounds like a word anymore
wow whar a relief I'm not the only one!
Buffalo buffalo buffalo buffalo... Oh wait, that’s something else.
Vsauce! Michael here. What you experienced is what we call "Jamais Vu". It's what you experience when a word has been spoken so many times that it loses its meaning. Thanks for watching, this has been Michael... or am I?
yeah its called semantic satiation
I relate to this on an existential level with other words.
The smartest person seems to be the person who comes up with the question with the answer in mind. Honestly takes a lot of brain power to come up with a problem and solution a lot of people cant solve
@@Naughty_Squad Which is why mathematics and linguistics are bad bedfellows.
@@Naughty_Squad I disagree, the problem itself is very simplistic and makes sense what is being asked. All you need is logic.
I had 8 races with the 2nd place finishers do the 6th race, then eliminated half the field, then did 2 more rounds to be sure there were no stragglers in 3rd place. Elegant solution!
As a project manager: “Build a stopwatch then we can time the horses”.
Doesn't work in scenarios where a stopwatch can't exist, e.g. in distributed systems. Ref Logical Clocks, from the 1970s.
@@davidhawley1132 ok thanks David. I’ve noted your assumptions. I’ll speak to the client in relation to your concerns of legacy constraints and find out if these are going to be problematic... I have liased with them and it turns out that we live in 2021 and we’re dealing with a startup. It’s also apparent that there are already timing tools available on the market, so I’ve conducted build vs buy analysis and it makes sense to procure the stop watch instead. $3 from Amazon. Since finding the fastest horse is going to be repetitive it also means we can make huge time savings in efficiency across the product life cycle and there is less risk involving the horses. So I’m grateful for your input as this led to a cost saving of tens of thousands. I’m giving you a pay rise and I’ll write a case study based on your input for lessons learned in the next knowledge sharing workshop so we can all benefit from your unrivalled wisdom.
Lol obviously this was not a serious solution dude.
@@lukeh7854 Code bootcamp grads would try to pull the move you suggest. My Comp Sci degree was in the Math dept, and we studied problems like this.
@@davidhawley1132 We have "stopwatches" that work just fine in distributed simulations. It's a very difficult problem with an embarrassingly simple solution. (But, I'm also talking software - getting circuits in time without a common clock is something I'm not going to mess with, unless performance is not a concern.) (And who wants to work on something where performance is not a concern?) :D
@@xnadave It's a classic problem with a good-enough solution. But from the comments, I bet few posting here even know there is a problem.
I got 8 because I didn’t think to rearrange the groups based on the results of the 6th race. I was adding an additional step where all the 2nd place horses from each group raced but it was basically an inefficient way to get the same result that you’d get in the 7th race in this solution.
Had the exact same thought process, but a total eureka as soon as the video said "we split them into groups" and I went "OH WAIT WAIT WAIT IS SEE IT no point in racing the nr 4 and 5 horses from the winner race, that frees up 2 more slots!"
@@codrincx same and i got stuck on how to fit a3 in there cos what if all 3 fastest horses were in the same race, you dont need to race the fastest again freeing up another slot *d'oh* 🤦♂🤦♂🤦♂
me neither!
@@codrincx i have a question: at this part 7:40, what if e2 < d2 < b2 < c2 < c1 < b1? And what if b2 < c2 < d2 < e2 < e1 < d1 < c1 < b1?
@@onepun9583 If I'm understanding your comment right, then:
The d and e group cannot imaginably matter, since after the first races, we know for sure that a1 > b1 > c1. Therefore, any horse from group e will be slower than *both* b1 and c1. The only horses that could be faster than b1 come from group a (as all horses in group c, d and e are all slower than b1), and then the only horses that could be faster than c1 come from groups a and b.
Notice that in both scenarios you've written, b1 and c1 are the fastest, therefore the only ones actually relevant. If a2 or a3 (could also be a4 or a5, but we only care about top 3) isn't faster than b1, then b1 *is* the 2nd fastest horse. Similarly if b2 isn't faster than c1, then c1 *is* the 3rd fastest horse.
I had thought 6, but since you can theoretically get 3 horses faster than the 3rd fastest from the first race in each subsequent race, a minimum 7th race is required to resolve the final rankings (and possibly several more).
My original bid was 11 - 5x5, and then 5x3 gives the fastest 9 horses. The 3rd fastest from the first of these races signposts the contenders from the remaining 4, which can be re-raced with the fastest two from the previous race in the final race.
They said minimum, meaning best scenario. So minimum is in fact 6. Run 5, then use 3rd place to run against the other 20. 3rd place beats all therefor you had your fastest 3 in only 6 turns
@@SharamanONorgannon you are assuming that the 3rd fastest from the first race is the 3rd fastest *overall.*
What if horses #17 & #19 are faster?
Sure - one of these is faster than the other, but you can't know whether both are faster than the 2nd fastest from the first race without a re-race. So now you have the 4 fastest horses, and don't know which of these are the 3 fastest - in fact, you don't even know which *single* horse is the fastest.
@@testname5042 They said best case. So you test the 3rd best from the first set against all the rest. In best case scenario the 3rd fastest from the first race IS the 3rd fastest overall therefor in 6 turns you can figure it out.
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now which is the eliminated ones and couldn't race to know for sure. so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
It’s honestly amazing how much a visual image can help someone figure out the solution. I ended up coming to the right answer just by visualizing it and thinking of the steps I need to take. A pen and paper also definitely helps 😅
my first idea was like " well, you need atleast 6" but seeing how you solved it, makes total sense. thank you for enlightment!
I knew it was at least 6 to find the fastest, and I was sure that there was a way to do a seventh where you get the 2nd and 3rd, so the right answer was _probably_ 7. I didn't reason out the exact way to _do_ the 7th race, but I didn't need to bc I knew it was possible. I don't know how some people got 11 or 12
@@westofley 11 comes from racing 5 horses, then removing the 2 slowest and inserting 2 others until you have only the last 5 horses in which case the top 3 are the fastest 3 overall. You need to drop 22 horses in total, 2 horses per race means 11 races using this strategy.
@Wesley Pardo I still think it's 6 races total, 5 races to get top 5 from lot of 25 and from that lot of 5 you'll get 1st, 2nd and 3rd as it's mentioned in question that you'll get " printout with the order the horses finished" so that'll be the fastest three in the order provided in the printout.
@@vishulangeh8348 you don't know relative times so it's possible the horses that came in second and third for the first race are faster than all of the horses in other races. Assuming the second and third horses in the 6th race are faster than those horses from the first race is unjustified
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now but they got eliminated so can't race horse 3rd place so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
I’m rethinking this and hadn’t realized that the 2nd and 3rd place horse would be from other groups. I take back my comment about there being a logic flaw. Mea Culpa!
6 races
@@babarshahzad7967 not enough.
@@babarshahzad7967 Explain one by one what you think these 6 races would be
I couldn't figure it out, but it's very interesting. I was a bit confused as to why the last race has to include only from groups a,b and c, since groups f and e might have been faster, but then you said you named those groups after you placed them in order of their respective winners from fastest to slowest and it now makes perfect sense. It's a bitter sweet feeling realizing this elegant solution but at the same time failing to figure it out on your own.
Yeah I had to think that through twice too; don’t feel bad
Its a really good logical problem. I got it wrong at first suggesting 6 races.
@@joelpwwsame.. I was like from the last race just pick 1st 🥇 2nd 🥈 and 3rd 🥉 but then ℹ realised there’s no way to tell if the 2nd horse from the last race was actually faster than the 2nd from the first race. So it’s prolly 7races.
Practice is most of that. Since you need very hard "gatekeepers" in your head that refuse you accepting a solution too early.
That doesnt make sense indeed, even they are in group a doesnt mean they run faster than others, eliminating d and e is wrong
There is a way to know the 3 fastests in 6 races IF you are very lucky. But that falls into the minimum definition, so it would be the best answer that I can think of now. That method implies selecting the 3 fastest horses from the first race, separete the first two and run the third to compare with other 4 horses. If that horse wins all the next 5 races, ypu discard 4 horses each race. And in 6 races you ensure you have the 3 fastest IF you were lucky enough to include them in the first race.
Great find! Your algorithm works and can identify the 3 fastest horses in 6 rounds (if you’re lucky). It would be worse most of the time, depending on how you choose to race the horses that win over the 3rd place horse.
A solution similar to this occurred to me as well. It would eliminate 2 horses in the first race, then 2-4 in races 2-6. The best case scenario is it would give you 3 remaining horses, worst case you’d have 13. It’s possible you could optimize further, but I doubt you’d get an average significantly below 7, and probably somewhat above.
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now which is the eliminated ones and couldn't race to know for sure. so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
Lazy solution: run 11 races and eliminate the 2 slowest each time. 22 eliminated, all that's left are top three
This is the correct answer because there is no fact that the 2nd, 3rd, and 4th heats are any faster then the first three winners.
This is what I came up with
I get a paper and label the horses so and I based my time on the fastest one in each group so then I can tell which ones are the fastest Ones ( I will race the fastest of each group to see which one is the absolute fastest and based the speed on that one
My best answer would be run a horse race gambling game while doing the laziest solution done everyday making sure to keep horses always healthy, do it for 6 months to a year, you get money and you get the best horses trained after months of running 🥳.
Since the fastest horse now wont necessarily be the consistently fastest horse, you need reliable statistics!
That's actually the correct answer, because it's said you don't have a watch, so you could never compare the times of each group's fastest horses, 2nd, 3rd, etc (one race at a time, remember?) The 2nd place from group A may be faster than group B's fastest horse.
The guy who made this video may be good at math, but he surely lacks text interpretation...
Kill 22 of the horses, then by default the remaining 3 must now be the fastest
So you're proposing mass destruction of company property during an interview?
@@brianvalenti1207 I think you mean "streamlining equestrian surpluses"
You would never get a job with that I guess ...
@@abhiramp7094 Hey, this man just solved how to prevent a food shortage. He must be hired.
@@Aniaas1 Cultural fit: 4.0
I got the setup exactly the same up until the 6th round, but at the seventh round I couldn't quite get the final 2 horses. I thought c2 could be faster than a2 and b2 and got confused how I'd identify the 2nd and 3rd fastest horses with such complexity. What I missed is that c2 could infact be faster than a2 and b2, but it's irrelevant as in that case there is still a1, b1 and c1 faster.
Looking at it from the other side and eliminating all the horses that can not possibly qualify for top 3 is by far the easiest and smartest solution. I didn't come up with that.
Exactly, also this implies how subjective is categorizing letters a to e in the same group as 2 to 5 since there is no timer, there's no way to know if A2 is actually faster than E1 because E1 could've for example finished in 5 seconds, A1 7, but that doesn't mean A2 couldn't have finished in 4.9 making it actually slower than E1
I still didn’t get it. C2 could in fact be faster than a1,a2, b1, b2. So we are missing that comparison.
But you said that is irrelevant so just want to understand what I’m missing.
@@bhupendrasatpathy C2 can never be in the top 3 because it is already slower than at least 3 horses: A1, B1, and C1. It is slower than C1 because it lost the race with all the Cs. It’s slower than A1 and B1 because A1 and B1 are faster than C1 since they beat it in the race of the fastest among groups.
But all of B2 3 4 5 just means they slower than B1.
All pf A2 3 4 5 just slower than A1.
Theres no line where B2 3 4 5 faster than A2 3 4 5 because groups are ranked by heats.
Say A1 is 10sec.
B1 is 9sec.
A2 3 4 5 could all be 4sec.
B2 3 4 5 could all be 8sec.
Nm
I forgot how many horses we were going for.
Fun question! I initially got 8, using the basic outline for the solution but was just racing the 2nd place race from the one with the fastest horse against the other 4 again for 7, and then used my 8th to run the next fastest from the group with the second fastest horse against the remaining 4. Was able to get the solution method after seeing the answer was 7, but not sure if I would’ve seen the optimization on my own, at least not without a pencil and paper
I paused and played the video only after solving the problem, now most important question is how much time does Google give in interview? 😁
2 minutes only
@@writer_gupta_ji wow, that is really hard
@@writer_gupta_ji*(edit this method is flawed as pointed out by others below me)*
I solved it in less then 2 minutes, tho I solved for 6-7 (ill explain that later) using a different method which is race 5 horses then race first place against 4 new repeat 5 times keeping track of the second place horses at the end of the sixth race if the fastest horse of race 5 isn't first or second then the top 3 are the 3 fastest else race 2nd place horse of race 5 against 3rd place of race 6 and first place of race 7 is 3rd fastest. This is a better solution because there is an 84.43% chance u will only need 6 races. *>>> AGAIN THIS METHOD IS FLAWED SO PLZ STOP COMMENTING THAT IM WRONG, I AM WELL AWARE.
i even solve this question only reading at thumbnail and then open video 😅
@@nothingnothing1799 Maybe I am missing something, but how does your method work? Imagine if your very first race had all three fastest horses in it, and you basically eliminate the 2nd and 3rd fastest ones at the very beginning, and never return to them in your procedure above, how do you get to the top three?
personally I thought it was 6, 25/5 for the 5 initial races and then 1 with the winners, surely first, second and third place meet all those requirements, 3 fastest horses, I hadn't thought about the fact that 2nd place in group A could be faster than 3rd place Group C in race 6, interesting, something to think about
Its 5 races...his answer its too complicated...and wrong...find my answer,to see the simpl logic...
Horse C in 3rd place beats 4th and 5th place horses hes faster than the eliminated horses even tho he never raced them from the 4th place group and 5th place Group at the beginning because the 4th and 5th already beat the 8 horses who got eliminated its obvious that horse in 3rd place faster than 10 so far counting 4th n 5th place. Horse 1st and 2nd beat everyone in their group the eliminated ones from there group never raced the horse 3rd place horse 1st and 2nd could had beaten someone faster than the horse in 3rd place now but they got eliminated so can't race horse 3rd place so we can't know for sure. All we know is 8 is left we can only pick 5 so 85% chance we need 7 try 12.5% chance we need a 6th try only.
First thought on this was 8. Race all groups (5 races), then race the winners of each (1 race) then race the winners again replacing the fastest overall with the runner up in the group repeating twice (2 races) Didn't think to remove the e and d groups like you showed and let them keep racing even though they could never be top 3
1:33 I was able to get a 10-race solution. Racing , and thereby sorting the 5 rows of horses, I obtain 5 columns, the last two of which can be discarded as they definitely don't have the 3 fastest horses.
I sort the 3 columns, and I obtain a group of 6 horses, of which I know the 3 fastest exist. By racing two different groups of 5 of the 6 horses, you can figure out which are the fastest over all.
My first idea was taking the 2 slowest off each time as well. Ended up with 11 races however I appreciate it can be done in less.
But upon further contemplation I figured if I'm at Google I'd just pick 3 random horses. The truth is what we say it is.
Same idea here. A way with less races may possibly exist, but designing and verifying its veracity likely takes longer than the few races that it might save us, so we better simply get those horses to run.
One could ask the interviewer, "is the question here really about the best algorithm, or is it about figuring out which are the three fastest horses in the most efficient way?"
yes man. you got it with 11.
The problem is that you dont have a time/ watch nor a distance! If you let 5 groups run, and you take the 1st. of each group, you can not be sure if these horses are one of the fastest 3. 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! . you have to have a constant to really get the 3 fastest! My logic: So you let the first 5 race, then you let the first second and third place on the track and get 2 new ones in, every race the 4,5 will be replaced. with this method you have always a constant for first, second and third place without needing a watch ! each race, 11 in total , will naturaly eliminate 4 and 5 place ! imagine this: lets say the first group are the 5 slowest of all, so the slowest up to the 5th slowest of all. in the second race the 4th and 5th place gets replaced with (in this simplyfiyed case)faster ones, and maybe one is the fastest of all and the other one the 2nd fastest of all. they will be 1st and 2nd place of the 2nd race and they will stay on this position. the 3th will be found after all other races are finished. You can switch the start situation, that the first 5er group have two of the fastest of all in it, so the first and second place will be set after the first race, and again the other races and just to find the real 3th place.---- i think its 11 races ! 😃
I started out saying 10, then realized I could eliminate the 4th and 5th place horses from the first 5 races. Just as I was patting myself on the back and saying the answer was 8 races, the rest of the video played. Guess I'm not as smart as I thought I was.
@@johns9652 6 races, because reality isn't so comfortable; you have the winners run, and the winner of winners is the fastest with 2nd & 3rd place marked behind it.
If UFC, or other events operated like y'all are suggesting, then all competition sports should be eliminated, and all champions should return their trophies.
I used that approach initially. 25 horses to start, 5 races, two slowest eliminated each race, 15 horses left. 3 races, two slowest eliminated each race, 9 horses left. 2 races, but with nine horses, you'll have one group of five and one group of four, and you need to keep the fastest three from each group, so eliminate the two slowest from the group of five, but only one from the group of four. This creates somewhat of a dilemma, as you have already run 10 races and you still have 6 horses.
Run a race of five, with the sixth sitting out. Knock out the two slowest from that group, leaving the three fastest and with the one that sat out, that's four remaining. That was 11 races so far
The final race will show who is 1-2-3 out of the original 25. But that was 12 races.
I understood how you got the three fastest horses in seven races (in a few minutes after I finished watching the video). I drew the diagrams you drew, and I began eliminating horses.
Its not correckt! The problem is that you dont have a time/ watch nor a distance! If you let 5 groups run, and you take the 1st. of each group, you can not be sure if these horses are one of the fastest 3. 1st horse in group (a) maybe can run just 2Kmh and the 1st of group (c) can run 40kmh while 2nd of group (E) can run 60 kmh! . you have to have a constant to really get the 3 fastest! My logic: So you let the first 5 race, then you let the first second and third place on the track and get 2 new ones in, every race the 4,5 will be replaced. with this method you have always a constant for first, second and third place without needing a watch ! each race, 11 in total , will naturaly eliminate 4 and 5 place ! imagine this: lets say the first group are the 5 slowest of all, so the slowest up to the 5th slowest of all. in the second race the 4th and 5th place gets replaced with (in this simplyfiyed case)faster ones, and maybe one is the fastest of all and the other one the 2nd fastest of all. they will be 1st and 2nd place of the 2nd race and they will stay on this position. the 3th will be found after all other races are finished. You can switch the start situation, that the first 5er group have two of the fastest of all in it, so the first and second place will be set after the first race, and again the other races and just to find the real 3th place.---- i think its 11 races ! 😃
@@crashoverwrite5196 Yeah. My first thought was to do what you described, but I abandoned that quickly because I knew it would require more races than necessary. I figured it out quickly enough. The answer is 7. Just pay attention to what is said in the video.
Now stop eliminating horses before it's too late!
Have you considered career in CS and interview with Google?
@@crashoverwrite5196 What about if you ran the first 6 races as described in the video but for the seventh, ran all 2nd place finishing horses from the first 5 races against one another and for the 8th (and final race) run the top two horses from both of the 6th and 7th races?
How about n horses? And we are only allowed m horses in each race. Is there a general formula for this?
Great question! Thumbs up, so Presh can notice it.
and we need to find the top x horse
I'm not sure about all combinations of numbers of horses etc, but the method in the video works for ¼(k-1)²(k+2)² horses where you can race ½(k-1)(k+2) horses in each race.
I think it's more adequately written as (½(k-1)(k+2))² horses and ½(k-1)(k+2) horses per race.
That makes it more obvious the former is the square of the latter.
+codebeard Is k the number of horses we're trying to find, or is it just a coincidence that k=3 for 25 horses? If k is the number of horse we're trying to find, the minimum number of races is ½(k-1)(k+2) + 2.
Mechanical horses make so much more sense, in the beginning I was thinking of actual horses where you'd have to consider how many races each individual horse ran to make it fair in comparison
lol
Yeah this generally applies to a lot of tech interview questions: there might be a simplifying assumption that needs to be made, and it won't always tell you what that is. If horse performance is variable, the question doesn't really have an answer, or it has a complicated answer with probabilities. With the information that's given, always take the simplest version of the question you can-that's usually what's intended. You can explain: "Based on the wording of the question, I'll make a simplifying assumption here that each horse can be mapped to a single numerical speed value, and it doesn't change between races". That's the kind of thing an interviewer is looking for, it shows that you see how complicated it *could* get but you know you don't have enough information for that to be the intended question.
Yeah, in the real world there is no perfect solution, because the horses might perform better or worse on a given race for different reasons.. the dead slowest horse could be sick but normally be the best, some may have more stamina and thus do better in later races, etc..
Before reading comments or finishing the video:
Five initial rounds with five of the twenty five horses each.
4th place and 5th place from each race is removed, leaving the 1st, 2nd, and 3rd place winners. At this point any of those three could be our top three so we have to include them for now.
This leaves 15.
Sixth round pits the 1st place horses from the first five rounds against each other.
We can then remove 4th and 5th place, as they obviously can't measure up, but we can also remove the 2nd and 3rd place horses from their races since they obviously can't be faster than the top three.
We can also remove the 2nd and 3rd place horses from the race the horse that got 3rd in the sixth round came from since they also can't out-speed the top three.
Then we can remove the 3rd place horse from the race the 2nd place horse in round six came from since both the 1st place horse from round six and the two horses that out-sped it in its first round are faster than it, knocking it out of the top three.
Finally, we can remove the 1st place horse from this equation. We know it's the fastest because it out-sped all other horses which in turn out-sped all of the others together.
This narrows it down to five; 2nd place from round six, 3rd place from round six, the 2nd and 3rd place horses from the round the 1st place horse came from, and the 2nd place horse from the race the 2nd place horse in round six came from. The seventh round features these five horses, and the top two are 2nd place and 3rd place overall after the horse we've already singled out as being first place.
So my answer is 7.
i came up with 7 as well. but in further thought i find myself with a different answer. what if horse a5 is faster than horse b1? there isnt a test race to prove that it isnt.
@@kajsorensen5652 the main point why a5 and a4 are eliminated is that even if they were faster than b1, rhey are slower than a1, a2 and a3 so theres no point in even pitting a5/4 in there
"Five initial rounds with five of the twenty five horses each.
4th place and 5th place from each race is removed"
No, the 5th horse in one group can be faster than the 1st horse in another group.
@@muhammadshafieebinkhaidzir6371 thank you so much! I couldn’t understand why he eliminated a4, a5, b3, b4, b5 and c2-c5 but your simple and succinct answer made it so clear. Thank you again!
@@davemillan3360 so what? They can’t possibly be in the top 3 so why continue to race them
Better solution : sell all the horses and buy a motorcycle if you need speed.
Edit : dont forget to buy a watch if you don't have one
What u gonaa do with speed and time when u don't have brain
@@BabyIshii i have a brain which can atleast understand a joke which u couldn't. 🤦
@@E7visuals ohhh my bad...I didn't know ur sense of humor died as well
that's what how you solve the problem after you get the job. *because Google $$$$$
I'm genuinely curious what percentage of people still have watches. They seem kind of redundant now TBH. Edit - and by have I mean "actually wear and use". Buried in the couch or the back of a junk drawer isn't what I'm talking about.
Nice puzzle, my first instinct was 11, should have thought about it more to think about what the results of the first five races meant. I thought about racing the fastest, but glossed over that eliminating the slowest two also limited the other four that were in their original groups AND the slower horses in the other groups.
11?💀
Yeah i also think its 11 by eliminate every horse on 4 and 5 spot. And i think about this just under a minute. But yeah if i had think long enough and do critical thinking i could arrive at the answer for 7
11 seems correct. The solution of this video does not seem correct. Without racing #2 of race 1 against #1 of race 2, how does one know that #2 of race 1 should be eliminated? What if all 3 fastest horses were in fact within race 1, but #2 and #3 of race 1 were inadvertently removed from subsequent comparisons against all other slower horses?
@@thangd7124 a2 and a3 are competing in the final race. Rewatch the video.
@@thangd7124 yeah 11 is also correct. The solution in this video is correct too.
In step two, because we already found the fastest horse in the group of 25 (1st place of the group "a"), we know that the 3 fastest horses might be all three in group "a" (case 1).
In group "b", we only consider 2nd place and 1st place horses, we remove the 3rd place horse in this group because we only need to find the 3 fastest horses (one is known in group "a"), now the 3 fastest horses might be "1st place group a, 1st place group b, 2nd place group b" (case 2).
In group "c", we consider only the 1st place horse, the 3 fastest horses might be "1st place group a, 1st place group b, 1st place group c" (case 3).
At 7:21, we have three cases to consider knowing that the fastest horse is 1st place group a horse.
case 1: 1st place group a, 2nd place group a, 3rd place group a
case 2: 1st place group a, 1st place group b, 2nd place group b
case 3: 1st place group a, 1st place group b, 1st place group c
The three fastest horses could be in one of the cases, but we don't know which case. What we know is the 1st place group a horse is the fastest. Therefore, we can leave out the 1st place group a horse and race the others to find the second and the third fastest horses.
case 1: 2nd place group a, 3rd place group c
case 2: 1st place group b, 2nd place group b
case 3: 1st place group b, 1st place group c
race 2nd place group a, 3rd place group c, 1st place group b, 2nd place group b, 1st place group c
What a genius. The creator, the man behind this video, and whoever got the answer right
The 7-race method in the video works, but the video never actually proves that this method is the most efficient though.
My one issue with the 5x5 grid of slowest/fastest winners was I thought to my self "How do you get that after 5 races???" But then I realized that the 6th race will tell you who was the fastest and slowest of winners. Great stuff.
This part is key and I don't think it get's the attention needed in the explanation. 5 races is minimum to race each horse at least once, and the 6th race is key because not only do you get the winning horse, but you also get the ordering of the groups. This allows you to determine the horses for the last round no. 7. Without the info from race no.6 you have no way to compare the groups between themselves.
@@Productlivity_ZZ I don't get why you even need the groupings though.
Wouldn't the top 5 winners already be the fastest of their groups
So you only need to race the winners to get the fastest horses.
Never mind I think I see now
@@izzy123123123 If the three quickest horses happen to be placed in group a, the third horse of group a could be faster than the winner of any of the other groups
@@siepie830 yeah it was more like representing their group but because they lost in their final race their group is eliminated
I got stumbled at "5 races give five " Fastest" Horses from each group, and the fastest among them is the first overall. But how exactly do I proceed with the 2nd and 3rd? " And I am happy about your explanation
Damn I feel like I got pretty close. I immediately had 2 ideas. The first method was to just keep the top 3 and add another 2 new horses until complete, which is 11 races. The other idea was to use a bracket and I figured out to get the fastest overall requires 6 races, but for second and third place I just did the same thing and compared the second fastest from the winner's group to the second fastest from the initial groups which gave me 8. Intuitively I could feel this was wrong though, and if I had actually wrote any of this down instead of trying to solve in my head I probably would have done a lot better, but even still I'm not sure I would have seen that last step. What I've learned here is knowing when and how to use grids can be extremely useful, and that I should note things down.
How did you determine the top 3 fastest groups? In my opinion, it would require a total of 8 races. The first 5 races would be used to divide all 25 horses into groups, then an additional race would be conducted with the fastest horse from each group. Next, another race would involve the second-place horses from each group, and finally, a race would be held with the third-place horses from each group.
by sorting race 6.
its by the order the 6th race finishes in. The horses that finish 4th and 5th in this race obviously are not in the quickest 3, and the other 4 horses in each of thier groups obviously are not either, so thats 10 nags eliminated. That leaves 9 horses (as you also eliminate the slowest 2 from every group). The horse that finishes 3rd is slower than the horses that finish 2nd and 1st in this race, and faster than all the rest of the horses its its group, so them 2 are eliminated. The horse that finishes 2nd is slower than the winner, so the horse that finished 3rd in THAT horses group is eliminated since we know there are at least 3 faster horses. That leaves 6 horses, so you race all but the known winner, and the final 2 are the horses that finish 1st and 2dn in this race, plus the winner of race 6.
I loved this resolution. Math is beautiful.
It would have a lot of pressure since it’s asked during an interview
And that's when you pull out your horses
I suppose that's the point in the interview more than any other thing.
Thank you for this video! Really fun question to figure out!
I didn’t look at the explanation part of this video so I would like to comment my thought process before I took a look.
I applied a few concepts that are helpful when solving riddles or questions.
1. Breaking down into components
2. Considering extremities to draw insight
I first thought of what would happen if we raced 5 horses? Solution is easy, the top 3 of the horse raced since there are only 5.
Now what if we considered 10? We test both of these groups out but we can immediately realize that 2 tests aren’t enough, even 3 or 4 is unlikely.
This because we can think of extremities. I thought of several scenarios in my head:
Maybe group 1 is a group of well bred horse that are extremely fast, and group two is a group of horses that are extremely slow. Great then the fastest 3 horse would be in group one. But wait no that seems wrong, what if one of these well bred horses accidentally got mixed into the batch of slower horses? All of a sudden the fastest horse of all might be the fastest horse in group two.
Insight: This means I have to test each group of horse to determine the fastest of each group, or there’s no way I can be sure.
Insight 2: If I compare the fastest horse from each group I can maybe get a ranking for the top 3 horses!
After running this through my head I realized that we would never have to test the 4th and 5th of this group again, since they weren’t in contention for the top 3. This frees up two spots for us to test!
Insight 3: We no longer have to test the 4th and 5th of any group any more (Since the fastest horse will always be in the top 3)
I then ran some more scenarios in my head. The next logical test would be to put the next two fastest horses (2&3) in group 1 (the fastest horse group) into the test.
This way if the 2&3 from group 1 are ranked the highest then we’re good to go! But what about 2&3 from group 2? Let’s apply some extremities. Group 1 horse 1&2 are super fast but 3 ah geez there could potentially be several more tests because there might be hidden fast horses in group 2. I might have to test the 2&3 fastest horse in each of the top 3 groups… If there’s a way to add another spot for testing this would significantly bring down the number of test I need to do. How can I do this?… Wait a second I just realized something… We never have to test the fastest horse in the group 1, since it’s the fastest horse in a race of all the fastest horses of each group, which means it’s the fastest horse in the entire race!
Insight 4: We don’t have to test the fastest horse in group 1, which frees up another slot for testing.
Great since we can now test 3 slots (We still need to included the fastest horse from group 2 and group 3) What should we test next?
We definitely want to test horse 2&3 from group 1 since thinking back to extremities they might be the fastest group containing all 3 fastest horse. The next logical candidate would be the horse 2 from group 2 as that’s the next fastest horse to test. Let’s run this scenario in our head to see if this works.
- If the horse 2&3 from group 1 are the fastest, then we have the solution. Horses 1&2&3 from group 1
- If horse 2 from group 1 is fastest, but horse 3 from group 1 is slow, then it would be horse 1 from group 2 that is third.
- If both horse 1&2 from group 1 are slower than horse 1 from group 2, then all of a sudden horse 2 from group 2 becomes in contention for being 3rd fastest horse. Since we’ve included that horse in the race we’ll still receive it’s ranking in relation to horse 2&3 from group 1. Nice we have that covered then
- The last possible case that can now happen is horse 1&2 from group 1 and horse 2 from group 2 are all slow, then horse 1 from group 3 would be the third fastest! There’s no more tests to be done as we’ve considered all extremities, and this looks to be the answer!
Let’s tally up all the races we’ve done.
- 5 races to find the fastest horse
from each group
- 1 race of the fastest horse from each group
- 1 more race to consider the top two horses from group 1 and top two horses from group 2 and too fastest horse from group 3.
This totals up to 7 horses!
Above was my thought process and I skipped to the peak replay in the video and found the answer was indeed 7! Happy I got the solution!
Entire process took about 20 minutes which means I would probably not finish this question during the interview (As well I might be too nervous) But it was super fun to solve!
Brb going to watch the video to see the thought process of the actual solution. Thank you for providing this video!
Wow upon watching the video drawing this out makes it a lot easier. I had process of elimination in my mind but was doing so progressively considering the next best candidates in the given scenario.
Approaching it from purely a process of elimination method makes this much easier to conceptualize rather than have to think the scenarios through in my mind. Drawing and eliminating would definitely be the best way to solve for this, but not sure if interviewers would allow for that.
All in all amazing video and a great piece of thought puzzle!
Good thought process, congrats!
One thing though: if there are 10 horses, and we can race 5 horses per race, then we can identify the 3 fastest horses (out of the 10) always in exactly _3 races_ .
Just have a try at this (much simpler) problem!
@@yurenchu You're right, if I had continue to explore this easier problem, I would have gotten insight 4 (We don't need to test the fastest horse) way sooner. This would have shaved off at least 5 minutes when answering this question. Good point!
I got 8 because I had a different interpretation of minimal. It takes at least 8 races to guarantee an answer, but can be done in 7 four out of five times.
6 races (five groups of 5, plus a "finalist" round) to find the fastest horse. You keep track of the 2nd and 3rd place finishers in each group. Whichever group the first place horse came from, the 2nd place horse from that group-stage races against the 1st place horses that remain (7th race). If a 1st place horse wins, then it is the 2nd fastest and which ever horse got 2nd is the 3rd fastest. If the second place horse from the group-stage wins, it is the 2nd fastest horse and the race must be run again with the 3rd place horse from the fastest horse's group-stage to find the 3rd fastest horse (8th race).
I got it! I checked a couple methods that ended at 11 races, but was brute force. So I drew a picture similar to yours and got to seven
I came up with 11 as well just doing it my head. Might have came up with seven if I wrote anything down to really visualize it.
@@sadlittleking2570 same here.
The 11 is so convenient, I hadn't thought that visualizing the problem can help
a simple way to approach this is understanding that the fastest 3 horses will be in the top 3 of any given subset of 5 horses. This means that if we can identify a subset of horses for which a particular horse would not be in the top 3 (proved by transitivity) then we can discard that horse. So after you do the 5 sorted horse groups, you find the order between their winners (6 races so far). All the horses slower than the 4th and 5th places from this last race can be discarded, together with their the 4th and 5th place horses as well (so 10 horses are gone). Then, all other horses that scored 4th and 5th place can leave as well. So we have 9 horses left. 1st place from 6th race is 1st place of all, so no need to re-evaluate that one. Now if you just try to attach the potential best score of every horse of the remaining 8, you will find 3 that cannot score better than 4th place. You are left with 5 potential horses which make for the 7th race
You win! The horses are in subsets in calc Not subgroups. Groups are social and biological not mathematical expressions.
I got that far, but didn't think to use the results of race 6 to rank the group's
Simple. Pet rock wins
25 - 5 = 20 horses remaining via the initial race.
The absolute best case scenario is that the initial 3 you picked were in fact the fastest 3. (Though given the information provided, you do not know for sure until all other horses are compared.) Thus they move on to be compared to the remaining. With that in mind...
Race 2: 20 - 3 = 17
Race 3: 17 - 3 = 14
Race 4: 14 - 3 = 11
Race 5: 11 - 3 = 8
Race 6: 8 - 3 = 5
Race 7: The final 5. Thus you will know for certain which horse is the fastest with the absolute minimum races required.
I couldnt really come up with why I would need the 7th race(after 6 races and I knew I had at least one more race to figure out the top 3 but I could not really come up with how to match up 5 horses for the 7th one) and now I can say I know why. Thank you.
My reaction to the original question: I go buy a stop watch. Work smarter not harder.
but then you wouldn't make as much money as the book keeper.
Use the timer on your phone
wow thanks for this answer i give it in my interview and now iam restricted to sit in any of the Google's interview😄...stating this is the dumbest posible answer anyone can give
@@borgir6368 I'm an employer, and "Get a watch" is the answer I want. Anything else is a waste of company resources.
Or even easier, borrow a watch.
Me to interviewer: "are the horses mechanical or do they get tired and slow from racing over and over?"
He said they are mechanical.
@@Guppypants Mechanical horses can wear down as well...
@@killerdinamo08 nope they won't u keep charging them after each race
@@pryo2460 I'm guessing you're the kind of person that yells at everyone when your Iphone Battery stops working, or your Electric Car starts to wear down, while shouting, "It's not broken! It was working just fine yesterday!"
Jokes aside, but "Mechanical" doesn't mean "indestructible, or immune to wear..." it means, "Consistent Performance on Repeated Runs." Even two Ford 150's aren't going to perform the same forever.
ok FUNNY
Up until your last race I'm with you. You still need 1 more race because logically horses a2 or b1 must be in 2nd but that doesn't help for 3rd. There are still 6 possibilities. You need to race these 5 to determine all three. Therefore the minimum is 8
No race needed.
I'd butcher 22 horses. Not only would the remaining 3 become the fastest by default but I could stack up on delicious horse meat and land the Google job for my out of the box problem solving.
If the Google Executives hire you, they may apply a similar method when it's downsizing time and they have to determine who their three most productive employees are.
yuri renner
The circle of life
@__ Drake,
Ah, of(f) course, The Lion King -- lions eat horses. ;-)
funny:)
Good luck eating mechanical horses haha
Curious-I was never good at math, and I have no interest in solving puzzles like this myself, nor any confidence that I could arrive at the correct answer. (I don’t work at Google.) yet I enjoy watching videos like this and am pleased to know the answer once it’s explained to me.
That's cuz you are homosexually attracted to me lol
It's a sorting algorithm. 5 races to sort them into a 5 queues of length 5, and 3 races to get the fastest from the head of each queue. Standard merge sort.
Sneaky, I get it. Good one.
This wouldn't work if, for an example, the three fastest horses among all of them were in the first queue.
@@tipadaknife But you only race the second and third because you already know the first is the fastest.
@@JohnWilliams-channel - But were looking for the 3 fastest horses. not the fastest - Example - race 1 in won in 60 seconds with the 2nd horse taking 61 seconds and the 3rd horse taking 62 seconds. All other 4 races are won in 64, 65, 66 and 67 seconds.
If only the winners are taken through to the next round then the two horses running in 61 and 62 seconds will not get through.
You need to take the first 3 runners (15) through to the next round of 3 races, after which (8 races) you're left with 9 runners.
You need another 3 races to get the 3 fastest - 11 races in total.
@@martinkil50 So the first 5 races determine the order of the horses in each race. The 6th race determines who is the fastest among those 5. The 7th race takes 2 and 3 from the fastest group, 1 and 2 from the second fastest group, and 1 from the third fastest group. You don't need to race 1 from the fastest group because you already know it is the fastest. In the 7th race, the ones that come in 1st and 2nd are the 2nd and 3rd fastest horses respectively.
Always makes my day when i'm able to solve one of these! ^^