Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a program to find the shortest path in an unweighted graph using BFS.

Hard

Problem 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 }
Log in or sign up to run or submit your code.Log inSign up
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' ]