Broadcom interview question

leetcode and the horse race problem