Interview Question

Country: United States

Comment hidden because of low score. Click to expand.
of 2 vote

A graph data structure will best fit this need. To really understand why, start with a single linked list. Assume the head of the list is a given URL, or a given time stamp signifying the start of observation or entries in the log.

Then the next node that follows will be the next time stamp that the same URL was visited (assuming head = URL). And the next another time stamp. This goes on. When you traverse from the head, you will know that this given URL was accessed in sequence at these time stamps that follow.

Now, start with a time stamp node in the sequence. Branch out of the main link to point to another URL that was accessed at that same time stamp. Repeat the above steps for the URL as the head.

Soon enough, you will end up with a directed graph.

- whitenoise April 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

There can be many approaches to solve it.

As for URL example is concerned we can use the Linear proving mechanism of Hashing. for each URL we can append a new node of timestamp for everytime access.

However generally , the basic many to many relationship can be best represented by Graph ( Directed graph ).

- hprem991 April 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Graph data structure is useful for representing the many to many relationships.
Particularly array representation of directed graph is more suitable to store that data,
where we will use 3D array to represent the relations.

A[No.of URLs][No.of Time Stamps][2]

A[i][j][0] = 1, if URL i is accessed at time stamp j, else 0
A[i][j][1] = 1, if at time stamp j, URL i is accessed, else 0

- Vijay April 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

How do databases do this ?

- Anonymous April 27, 2013 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More