Description
Given an array paths where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city (the city without any outgoing path).
Examples
Input:
paths = [["London","New York"],["New York","Lima"]]Output:
"Lima"Explanation:
Lima has no outgoing path.
Input:
paths = [["Tokyo","Seoul"],["Paris","Tokyo"],["Berlin","Paris"]]Output:
SeoulExplanation:
Following the path chain: Berlin → Paris → Tokyo → Seoul. Seoul is the destination city because it has no outgoing path to any other city.
Input:
paths = [["Miami","Orlando"],["Boston","Chicago"],["Chicago","Denver"]]Output:
OrlandoExplanation:
There are two separate path chains: Miami → Orlando and Boston → Chicago → Denver. Orlando is the destination city because it appears as a destination but never as a starting point, meaning it has no outgoing path.
Constraints
- •
1 ≤ paths.length ≤ 100