Interview Question


Country: India
Interview Type: In-Person




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

* -- * -- *
|     |     |
B--C -- *
|     |     |
A-- D-- *

Lets take an example. In the grid shown above
min no of steps to reach C = MIN OF {min no of steps to reach B + 1,
min no of steps to reach D + 1,
if A is a special point then min no of steps to reach A + 1
}
Use this formula and start calculating min no of steps to reach each point on the right and top of the source point, skipping those points whose X and Y coordinate exceed the X and Y coordinate of destination.

- kr.neerav May 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can't it be done by DP table ?

- numid June 02, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is one of the simple DP problem

- GS July 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can build a partial order on the special points. A point is bigger than another point if both its x and y coordinates are larger.
The answer is the longest path in graph build base on this order. Generally longest path is NP but this is I think a lattice which means that you can do it in poly time. Unfortunately I don't remember the algorithm for it.

- navid May 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can build a partial order on the special points. A point is bigger than another point if both its x and y coordinates are larger.
The answer is the longest path in graph build base on this order. Generally longest path is NP but this is I think a lattice which means that you can do it in poly time. Unfortunately I don't remember the algorithm for it.

- navid May 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

So, assuming the points have x and y coords and the destination is always reachable from the source (simple check that x,y of destination> x,y source), without the special points, it would be simply a case of going right till Xcurr=Xdest and then up till you hit the destination.

With special points, the trick would be to maximize the number of special points you hit. This can be done by simply starting from your current position, using an unweighted shortest path algorithm, and finding the closest special point. Then go right until Xcurr=Xspecial and then up till you hit special, jump across, and then use this as the next source, until we find that no special point is within the bounds of having it's X coord< Xdest and it Y coord<Ydest and therefore we can just go right until Xcurr=Xdest and then go up.

- calvin.brizzi May 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It seems that "finding the closest special point and go there" may cause you to loss several special points with less Ycurr.

- zhao.nanjing May 21, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

(sorry typing from mobile)
You're right, I somehow thought that it would work, but I could potentially miss a better path. Uhm, can't think of a way to do this without finding all special points first..

- Calvin May 21, 2014 | Flag


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