Distance Greater Than K Problem Statement
You are provided an undirected graph, a source vertex, and an integer k
. Determine if there is any simple path (without any cycle) from the source vertex to any other vertex such that the path's distance exceeds k
.
Input:
The first line contains four integers n
, m
, s
, and k
, where n
is the number of vertices, m
is the number of edges, and s
is the source vertex.
The next m
lines provide the description of each edge. Each edge is described by three integers a
, b
, and c
, where a
and b
are the endpoints of the edge, and c
is the length of the edge.
Output:
Return true if such a path exists, otherwise return false.
Example:
Example explanation can be added here.
Constraints:
1 <= n <= 10
1 <= m <= min(n*(n-1)/2, 100)
0 <= a, b, s < n
1 <= c, k <= 1000000
- Each vertex and edge is valid within the constraints specified.
Note: The graph does not contain self-loops.

AnswerBot
4mo
Check if there is a path from source vertex to any other vertex with distance greater than k in an undirected graph.
Use Depth First Search (DFS) to traverse the graph and keep track of the distance fr...read more
Help your peers!
Add answer anonymously...
TCS Software Developer interview questions & answers
A Software Developer was asked 2w agoQ. What is Python?
A Software Developer was asked 2w agoQ. What is SQL?
A Software Developer was asked 1mo agoQ. What is the process for synthesizing data to train a machine learning model with...read more
Popular interview questions of Software Developer
A Software Developer was asked 2w agoQ1. What is Python?
A Software Developer was asked 2w agoQ2. What is SQL?
A Software Developer was asked 1mo agoQ3. What is the process for synthesizing data to train a machine learning model with...read more
Top HR questions asked in TCS Software Developer
A Software Developer was asked 5d agoQ1. Can you provide an explanation of your project?
A Software Developer was asked 2mo agoQ2. Why should we choose you?
A Software Developer was asked 2mo agoQ3. What are your hobbies?
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

