educative.io

Educative

Wrong Test Case or Solution

In the problem Challenge 8: Find Length of Shortest Path between Two Vertices
Test Case is given as:
(1–2,1–3,2–4,4–5,2–5).findShortestPathLength(1, 5)

The solution provided,
Solution Review: Find the Shortest Path between Two Vertices
does not work with this test case. The expected value of test case is 2. This solution returns -1.

Please try the solution with following main method:
public static void main(String args[]) {
Graph g = new Graph(5);
g.addEdge(1, 2);
g.addEdge(1, 3);
g.addEdge(2, 4);
g.addEdge(4, 5);
g.addEdge(2, 5);
System.out.println(findMin(g, 1, 5));
}


Type your question above this line.

Course: https://www.educative.io/collection/5642554087309312/5724822843686912
Lesson: https://www.educative.io/collection/page/5642554087309312/5724822843686912/4711577859129344

Hi there,
Kindly read this challenge and run again. It’s working well now. Node names are from 0 till 4.

In the challenge(Educative: Interactive Courses for Software Developers) the test case is with input (1–2,1–3,2–4,4–5,2–5).findShortestPathLength(1, 5). And your solution fails with this test case. Your solution does not work with this test case. Please check your solution with the test cases in the problem. I know your solution work with 0-4. But not working with the test case you provided in the challenge.
Please correct the test case or solution.

1 Like

You are right the solution does not work with the given test case. What I found out was that the convention followed was to define vertices as 0-N. I am not sure if this convention is mentioned explicitly in the course somewhere. The test case should be changed accordingly.

1 Like