You are given a list of directed edges, edges, where each element is a pair [u, v] representing a one-way link from node u to node v. You are also given a start node.
Your job is to follow the directed edges beginning at start until you land on a node that has no outgoing edges. Return that node, which is the destination.
The graph may contain several disconnected pieces, but for the provided input you can assume there are no cycles and exactly one destination is reachable from start.
Constraints:
start node, there is precisely one destination.Example 1:
edges = [["B","C"], ["D","B"], ["C","A"], ["E","F"]], start = "D"
"A"
Starting at "D", the path goes D → B → C → A. Node "A" has no outgoing edge, so it is the destination.
Example 2:
edges = [["A","B"], ["B","C"], ["C","D"], ["D","E"], ["E","F"], ["F","G"]], start = "A"
"G"
Example 3:
edges = [["A","D"], ["B","D"], ["C","D"], ["D","E"], ["F","G"], ["G","E"]], start = "F"
"E"
Example 1
Input: {"edges":[["B","C"],["D","B"],["C","A"],["E","F"]],"start":"D"}
Output: "A"
Example 2
Input: {"edges":[["A","B"],["B","C"],["C","D"],["D","E"],["E","F"],["F","G"]],"start":"A"}
Output: "G"