Interview Question






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

I assume each bus stop lies on at least 1 route. So let's say we have a table like RouteTable(BusStopName,RouteNumber). So if a new bus stop lying on n number of routes is added, we add n rows to this table.

1.For finding all the bus stops on a route,
select BusStopName from RouteTable where RouteNumber=?

2.For finding all the routes between bus stops s and d

select RouteNumber from RouteTable where BusStopName = s
INTERSECTION
select RouteNumber from RouteTable where BusStopName = d

If the above query returns nothing, there is no connecting direct route. In such a case,
1.you need to find out all the bus stops which lie on the routes having s.
2.Similarly find out all the bus stops which lie on the routes having d.
3.Find the common bus stops of steps 1 and 2 above along with their routes numbers for s and d.
4.The result of 3 would give you the change bus stop and the 2 routes which you would follow one after another to reach from s to d.

- sdm February 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks your solution will work. Step 1: as per ur defination of table we will get all bus_stop_names on a specific route but what if we also want them in order bus traverse them. I think one solution for this will be, add one more column having sequence_no like source as 1, destination as N and in between bus_stops will get corresponding number.

- dpka March 05, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think your solution with work for the first part. 
In the second part you are assuming that, there is a single intermediate (transfer) stop. Your solution won't work if there are two or more transfer points.

- Developer September 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The problem, as I understand, can be solved through using a graph structure.
If you have to use the Relational Database, you could create many-to-many relations between nodes(bus stop) and edges(with weight). Retrieve them into a standard structure (Directed graph) and then you could use standard algorithms (or methods) on the structure.

You could also use Neo4j (the Graph Database). It is easily expandable!

- shilo.kate February 26, 2010 | Flag Reply


Add a Comment
Name:

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

Books

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

Videos

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