BackmediumArrays arrays medium

Minimum Directed Hops Solution

Problem Statement

You are given a directed graph represented as an adjacency list `edges`, where `edges[i]` is a list of nodes that can be directly reached from node `i`, along with a source node `src` and a destination node `dst`. Find the minimum number of hops required to reach `dst` from `src` using the given graph.

Example 1
Input
{"edges":[[1],[2],[3],[]],"src":0,"dst":3}
Output
3

Explanation: The minimum number of hops required is indeed 3 following the path 0 -> 1 -> 2 -> 3.

Constraints

  • The graph can contain at most 100 nodes.
  • The graph is represented as an adjacency list `edges`, where `edges[i]` is a list of nodes that can be directly reached from node `i`.
  • The source node `src` and the destination node `dst` are guaranteed to be valid nodes within the graph.
  • The graph may contain cycles.
  • The graph may not be connected.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free