employer cover photo
employer logo
employer logo

Palantir Technologies

Is this your company?

Palantir Technologies interview question

How would you find the shortest path between two nodes in a graph? Write code in Java to do this.

Interview Answers

Anonymous

29 Aug 2015

This problem, if asked vaguely, aims to test the interviewer's knowledge of ALL shortest-path algorithms. For example, if I were the interviewer, I would ask more details about the graph: if the graph is unweighted, then a simple BFS will suffice. If the graph has negative weight, then dijkstra won't work. If this shortest-path query is going to appear multiple times, use Floyd-Warshall. If there is negative weight, or parallel computing is available, then Bellman-ford.

4

Anonymous

8 Jul 2009

Read Wikipedia for information about depth-first search, breath-first search, and breadth-first-search from both endpoints to give a good answer to this question.

1

Anonymous

12 Sept 2010

you can use dijkstra's algorithm... its very similar to building a minimum spanning tree using the prims algorithm

1