Bloomberg telephone screen.

bloomberg logo
bloomberg
April 6, 20253 reads

Summary

I had a telephone screen with Bloomberg where I was asked to design a data structure for a horse race with specific add and get methods.

Full Experience

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"]]

Interview Questions (1)

Q1
Design Horse Race Data Structure
Data Structures & Algorithms

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"]]
Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!