Horse Racing Duals puzzle discussion


if you want a container that inserts using operator [] then you should use map instead of list or vector


Hi all,
In Java, I was not able to pass the “Numerous Horses” validation by using a SortedSet (all other tests were green). Instead, I used an ArrayList as suggested by someone.
However, I performed some test on my side and if I add more than 50 numbers, the SortedSet is faster than the ArrayList. With less than 50 numbers, the time are equivalent.
Does someone have an idea why a List is better for this test than the Set?


The purpose of a set is to maintain the uniqueness of its elements. In this puzzle duplication of data is allowed (two horses have the same strength). Using set as container can give incorrect results. List is more suitable.

About speed, it is possible for the set to have removed duplication in the data set so that there are less data to process and seems to be faster to produce an answer, an incorrect answer.


It’s still possible to get correct results with the set with following simple addition:

if (!powers_set.add(horse_power)){
println(“0”); // horse with same power already exists


j’ai un problème concernant le 2eme test.
Je passe sans souci le 1er et le 3eme test mais le second me renvoi “2” alors que “1” est attendu.
Quelqu’un a-t-il déjà eu ce souci ? (je code en C#)
Merci d’avance. :slight_smile:


For 2nd test correct answer is 1, but your program printed 2 instead. You have to find a bug in your code


Well ! Thanks for this but I already knew it. I wrote it in my previous answer? But I don’t know why only this test doesn’t work.


What kind of help you are seeking for? If its test (not validator) then you can easily print inputs, then debug your code with these specific inputs.


I was looking for someone who had the same problem and solved it. Don’t worry I know how to use debug :slight_smile: but can’t find my error anyway.


I can take a look. Send me the code via personal message


I have problems at validators stage, while basic tests being ok. It’s not speed: I failed “Only 2 horses” too. Is there a way to know reasons and/or see test data for validators?


Using JavaScript, I can’t get past the “Shorter difference on the first 2 horses” test. Every other one works fine and even when I test that case manually, it works fine.


Read the statement carefully again, you might have missed an edge case. If you don’t manage to pass it, I can send you the validator.


Well I don’t think this statement can be misinterpreted, it means the best solution is between the two first horses, I think. But it does work fine when I test this case.


When you solve the test case but fail the same validator, it often means that you made an assumption in your code that isn’t true. Perhaps you optimized for the exact scenario rather than making the solution more general. It can also mean that there is some edge condition that is not being handled properly, like Thibaud said.


There’s a missing detail in the explanation.

If there’s a single horse, the result is that horse’s strenght, rather than 0.

For example:

The result is 5, not 0.


single horse

the rules specifically said that “1 < N”. that means there are two horses or more.


Problem is my code only passed the last test after I considered this case; hence me posting it here :slight_smile:


I’ve just added following line of code to my solution but it still passes all the tests and all the validators:
if (N == 1) throw new Exception(); That means there is no case with 1 horse (as expected).

I recommend you to check your code one more time because you obviously misunderstood the puzzle rules.


for the one who are very desperate in javascript:
this sort allows you to check only the ones that are next to each other and it is enough …