Bloomberg telephone screen.

Anonymous User
1229
Apr 06, 2025
Apr 06, 2025

Design data structure for a horse race, where we will have two methods.

add(string horseName, int checkpoint)

Updates the position of the horse. This method will be called for all the checkpoints horse crosses. Checkpoints are in increasing order.

get()

Return name of the horses, one with the highest checkpoint first
When two horses are at the same checkpoint, print horses in the order which reached that checkpoint first.

Example.

Input.

["HorseRace","add","add","get","add","get","add","get"]
[[],["A",1],["B",1],[],["C",1],[],["B",2],[]]

Output.

[null,null,null,["A","B"],null,["A","B","C"],null,["B","A","C"]]
Comments (4)