Bloomberg telephone screen.
- Posted
- 6 Apr 2025
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.
How it went
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"]]
Questions asked (1)
- 01
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"]]