Final Challenge #1
Lesson 8 of 9 in Coddy's Breadth-First Search - Graph Algorithms course.
Challenge
MediumTime for the signature use of BFS.
Write a function named shortestPath that takes n, the flat edges array (undirected), a start vertex, and a target vertex, and returns the length of the shortest path (the number of edges) from start to target. If target is not reachable, return -1.
For example, on a path 0-1-2-3 the shortest path from 0 to 3 has length 3.
Try it yourself
#include <stdlib.h>
int shortestPath(int n, int* edges, int edges_size, int start, int target) {
// Write code here
return -1;
}