Write a program to find the shortest path in an unweighted graph using BFS.
HardProblem Statement
Write a program to find the shortest path in an unweighted graph using BFS.
Sample Input
Graph: { A: ["B", "C"], B: ["A", "D", "E"], C: ["A", "F"], D: ["B"], E: ["B", "F"], F: ["C", "E"] }
Start: "A", Target: "F"Sample Output
Shortest Path: [ 'A', 'C', 'F' ]
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
function bfsShortestPath(graph: { [key: string]: string[] }, start: string, target: string): string[] {
// Your logic here
}
Input
Graph: { A: ["B", "C"], B: ["A", "D", "E"], C: ["A", "F"], D: ["B"], E: ["B", "F"], F: ["C", "E"] }
Start: "A", Target: "F"Expected Output
Shortest Path: [ 'A', 'C', 'F' ]