
Asked in JUSPAY
Path Existence in Directed Graph
Given a directed and unweighted graph characterized by vertices 'V' and edges 'E', determine if a path exists from a specified 'source' vertex to a 'destination' vertex. The edges are represented in a 2-dimensional array 'Edges' where each entry Edges[i][0]
to Edges[i][1]
represents a direct connection.
Example:
Input:
Vertices: 4, Edges: 3
Edge List: [[0, 1], [1, 2], [2, 3]]
Source: 0, Destination: 2
Output:
true
Explanation:
There is a path from the source (0) to the destination (2) following 0 -> 1 -> 2.
Input Format:
The first line contains an integer ‘T’, representing the number of test cases.
The first line of each test case contains two integers 'V' and 'E'.
The subsequent 'E' lines contain two integers per line, describing the directed edge from 'Edges[i][0]' to 'Edges[i][1]'.
The last line of each test case specifies two integers, the 'source' and 'destination' vertices.
Output Format:
Output 'true' or 'false' for each test case regarding the existence of a path from the 'source' to 'destination', each on a new line.
Constraints:
1 <= T <= 5
1 <= V, E <= 10^5
0 <= Edges[i][0], Edges[i][1] < V
0 <= source, destination < V
- Time Limit: 1 sec
Note:
Implement the function; there is no need to handle input/output operations directly, as they are managed elsewhere.

AnswerBot
1y
The task is to check if there exists a path from a given source vertex to a destination vertex in a directed and unweighted graph.
Read the number of test cases.
For each test case, read the number of v...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Front end Developer at Other Companies
Top Skill-Based Questions for JUSPAY Front end Developer
CSS Interview Questions and Answers
500 Questions
Web Development Interview Questions and Answers
250 Questions
JavaScript Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
HTML Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

