Amazon Hackon Contest | Coding Question 2

Q1. https://leetcode.com/discuss/interview-question/2118740/Amazon-Hackon-Contest-or-Coding-Question-1

Q2. You have to find the shortest path between your location(0) and your office(n-1), You have given n which is the number of bus stops in nearby area, an integer k and a list routes which has k values denoting the start, end and bus no. for a stop.

Moving from start location and end location will cost you 1 unit for any bus and changing the bus from any stop will cost you 1 unit. Return the path with shortest Cost;

If it is not possible to reach the destination, return -1,

Test Case -

N = 5; k = 5;
routes = {{0, 1, 884}, {1, 2, 884}, {2, 4, 937}, {0, 3, 937}, {3, 2, 937}};

Ans = 3,
Shortest path cost 3 units
Path is 0 -> 3 -> 2 -> 4 in bus no. 937

The path - 0 -> 1 -> 2 -> 4 will cost you 4 units because at stop 2 you have to change the bus which will increase the cost by 1 unit.

I have used Shortest Path Algorithm using Topological Sort but i didn't able to pass few testCases.

Please help.

Thanks in advance.

Comments (3)