Bloomberg LP Interview Question
Senior Software Development EngineersCountry: United States
Well, one question is: Is the data stagnant or evolving over time?
If data is stagnant / bearly changes with time, I would use an ISAM (Indexed Sequential Access Method) tree or in the latter case, a B+ Tree. Both of these trees with startTime as primary key and name as the secondary key. This is because, the primary key is efficient for range searches (because it will be clustered) while secondary key is not. There are open source libraries available to build and maintain these datastructures.
For example: jdbm2 @ google code (Sorry could not provide actual link)
If able to use C++11, use std:: unordered_multimap to hash records by name, and std::ordered_set to organize records by time. GetDescriptions() can return a std::vector of const char* for descriptions, and GetRecords,() can return std::pair of const_iterators to range of records.
The assumptions here were that return values cannot be modified; drop the const if that is not the case.
Have a balanced BST holding records sorted on timestamp. The question will reduce to find nodes in given range in a bst. For descriptions keep a hash with values pointer to the nodes in the balanced BST nad return all matching descriptions.
- PB October 08, 2014