Horse Racing duels confusion

Continuing the discussion from Horse Racing Duals puzzle discussion:

Im trying to understand how to tackle this algorithm. like one of the test cases has 999 horses right, im assuming thats just ridiculously inefficient to loop through in its entirety. what the heck can i google to brush up on the logic behind this.

Summary

This text will be hidden

Did you click here already?
image