DEV Community

Discussion on: Can you solve the fastest horse 🐴 algorithm problem?

Collapse
 
leadersheir_ profile image
Warisul Imam

Here's the solution I thought of. Assuming we're not allowed to measure the speed and judge whether a horse is fast or not depending on whether it finishes first or not.
Conduct five races with groups of 5 horses and eliminate the last two finishers from each group, which will leave us with 15 horses. Repeat the process again - but this time it takes three races - and we are left with 9 horses. Repeat the process again - eliminate last 2 horses from the group of 5 and last 1 horse from thr group of 4 - and we're left with 6 horses, 2 races taken. And finally, take 5 from these, get the top 3 (1 race taken) and race it with the other one left and eliminate the last one leaving with 3 horses(another race taken).

Means a total of 12 races. Now lemme check the video...
Happy Coding!

Collapse
 
leadersheir_ profile image
Warisul Imam

Appears I actually got it right😅... Yeah tell me I looked at the solution or read it in the comments all you want...

Happy Coding🤗