Dsa
Graphs Dfs
Warm-up
City Path Planner
You are given a directed graph representing a city with intersections as nodes and roads as directed edges. Write a program to check if there exists a path from one specific intersection to another.\nInput Format: The first line contains two integers, N (number of intersections) and E (number of roads). The next E lines contain pairs of integers u and v representing a directed road from intersection u to intersection v. The input terminates with '0 0'. The last line contains two integers X and Y, where X is the starting intersection and Y is the goal intersection.\nOutput Format: Print 'YES' if there is a path from X to Y, otherwise print 'NO'.\nExample:
Input:
5 4
1 2
1 3
3 4
4 5
0 0
1 5
Output: YES
Key concepts
graphsdfspath existence
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now