Zillow Interview Question
- 0of 0 votes
AnswerImplement a class to provide in real-time the list of the top 100 most viewed
- chestnut304 August 14, 2015 in United States
properties in the last hour. For the purposes of this exercise, you should think of
"the last hour" as the 3600 seconds ending now. Properties are represented by a
"zpid" or Zillow property ID, which we will treat as a unique string.
Example, if the current time is 2:20:
| 1 | 2 | 3 | 4 |
|-------| <- we want this time range
One possible interface:
interface MostViewed
{
// Every user view of a property calls this:
void propertyViewed(String zpid);
//Anytime we want the top 'count' properties, we can call this:
//which returns a list of zpids
List<String> getCurrentMostPopular(int count);
}| Report Duplicate | Flag | PURGE
Zillow Data Structures
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
I would use a combination of a doubly linked list, a hash table and a min heap.
- Lively May 16, 2016The hash table maps from a property to its location in the linked list. The linked list holds the items in order, and when an item is viewed it is moved to the end of the list. The list also points for each item to its location in a min heap of size 100 (not all properties are in the heap). I would have a routine that would periodically remove items from the list based on the time (and update the rest of the data structures). When a property is viewed, it is added/updated in the hash table. It is put at the end of the linked list with its new time. Then we compare the number of views for that item with the top of the min heap. if it is larger, we pop the top of the min heap and insert the new item to the heap.