Dsa
Graphs Dfs
Easy
Network Path Finder
You are given a directed graph represented by an adjacency list, where each key is a node and each value is a list of nodes that can be directly reached from the key. Your task is to determine if there is a path from a starting node to a target node. Implement the function `find_path(graph: Dict[str, List[str]], start: str, target: str) -> bool` that returns True if a path exists, otherwise False.
Input format:
- The first line contains an integer `n` denoting the number of nodes.
- The next `n` lines each contain a string representing a node.
- The next line contains an integer, `m`, the number of edges.
- The next `m` lines each contain two strings `u v`, indicating a directed edge from node `u` to node `v`.
- The last line contains the `start` and `target` nodes separated by a space.
Output format:
- Print 'Yes' if a path exists, or 'No' otherwise.
Example:
Input:
3
A
B
C
3
A B
B C
C A
A C
Output:
Yes
Key concepts
graphsdfspathfinding
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