Google L4 | Banglore | Onsite
Anonymous User
2723
Lets say you have graph with same weighted bidirectional edges.
A <-> B <-> C <-> D <-> E
|                       |
|                       |
*---------F-------------*

Input is path between 2 nodes. eg You can travel from A to E with path A->B->C->D->E.
Compressed path of given path is ans so that your input path remains same ie you must travel along given path only but you can skip few nodes in representation.
case 1
eg. A -> C -> E
For going from A to C path is A -> B -> C and from C to E is C -> D -> E.

case 2
but A -> E is invalid because you can go from A to E with path A -> F -> E 

case 3
A -> D -> E  is also invalid because A to D can be A -> F -> E -> D and then from D to E with  D -> E which is now different from input path.

You have been provided with function which takes input as 2 nodes and returns shortest possible path.
You can assume it works fine and returns optimal answer.

Given input path find its most optimal valid compressed version.

Got vague question on google onsite round. Interviewer also didnt explain question fully. This is what I could get best based on clarifying questions I was asking. Apart from graph, there was no question also, he just gave description of question verbally.

I tried to have Binary search on given path to select nodes that are part of ans, but really could not come up with any valid ans.

Let me know if there's any standard way to approach this question.

Comments (6)