Bloomberg LP Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
Stock ticker store Company Stock name and their values, it also keeps tracks of trends as well.
I think what interviewer want to know is to produce one such trend, for example, increment since x in constant time,
One way to do this is to store the data in the dictionary with following format.
var stockticker = new Dictionary<string,Dictionary<DateTime ,double>>();
Now, we can store as many data as possible, and when asked from given point what is current trend, we can call the following function
public static double CurrentTrend(DateTime time)
{
// error conditions and time is not valid input goes here.
return ((dictionary[this.Name][this.LatestEntry] - dictionary[this.Name][time])/dictionary[this.Name][this.LastestEntry])*100; // for % result.
}
Both Name and LatestEntry are available in the Company class. This method will be implemented inside the Company class. StockTicker, will work as collection class here, which will call indivisual class based upon the requirement.
The the insert complexity is O(1), Figuring out any ratio between two times is also O(1) here.
I think they wanted to see how you would design this with your own classes. Using your own classes also means you can easily keep track of the highest value / lowest value in a listing as you consume the stream, getRatio() can then be O(1).
e.g.
- Anonymous December 18, 2016